Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry Push Development

Reply
Visitor
Posts: 1
Registered: ‎02-15-2012
My Device: 8520
My Carrier: 3012280065

Push services Produccion - The remote server returned an error: (502) Bad Gateway

Hola

 

Tengo un problema al tratar de consumir el servicio de blackberry desde .Net C# este es el codigo fuente

 

HttpWebResponse HttpWRes = null;
HttpWebRequest HttpWReq = null;

string pin = "26FFC557"; // or actual pin of device

string pin1 = "26EAF412"; // or actual pin of device
string pin2 = "26231A5D"; // or actual pin of device 
string applicationID = "117-5aa49e33eR0M53t04428162i10a82RR586h3";
string BOUNDARY = "PMasdfglkjhqwert";
string msg = "Prueba Ing. Oscar Fuquen Por favor Notificar Smiley Happy oscarfuquen@hotmail.com !!!!"; // the message to send

string userName = "117-5aa49e33eR0M53t04428162i10a82RR586h3";
string userPW = "Clave";

string url = "https://cp31177.pushapi.na.blackberry.com/mss/PD_pushRequest";

HttpWReq = (HttpWebRequest)WebRequest.Create(url);

SetProxy(HttpWReq); //if proxy needed, use this

HttpWReq.Method = ("POST");
HttpWReq.Accept = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
HttpWReq.Timeout = System.Threading.Timeout.Infinite;
HttpWReq.PreAuthenticate = true;

HttpWReq.Credentials = new NetworkCredential(userName, userPW);

HttpWReq.ContentType = "multipart/related; boundary=" + BOUNDARY + "; type=application/xml";

SetBasicAuthHeader(HttpWReq, userName, userPW);

StringBuilder dataToSend = new StringBuilder();
string deliverBefore = DateTime.Now.ToUniversalTime().AddMinutes(5).ToString("s", System.Globalization.CultureInfo.InvariantCulture) + "Z";
string ID = System.DateTime.Now.ToFileTime().ToString();
string myPushId = DateTime.Now.ToFileTime().ToString();

dataToSend.AppendLine("--" + BOUNDARY);
//dataToSend.AppendLine("Content-Type: application/xml; charset=UTF-8");
dataToSend.AppendLine("Content-Type: application/xml");

dataToSend.AppendLine("");
dataToSend.AppendLine("<?xml version=\"1.0\"?>");
dataToSend.AppendLine("<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP 2.1//EN\" \"http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd\">");
dataToSend.AppendLine("<pap>");
dataToSend.AppendLine("<push-message push-id=\"" + applicationID + "\" deliver-before-timestamp=\"" + deliverBefore + "\">");
dataToSend.AppendLine("<address address-value=\"" + pin + "\"/>");
dataToSend.AppendLine("<address address-value=\"" + pin1 + "\"/>");
dataToSend.AppendLine("<address address-value=\"" + pin2 + "\"/>");
dataToSend.AppendLine("<quality-of-service delivery-method=\"unconfirmed\"/>");
dataToSend.AppendLine("</push-message>");
dataToSend.AppendLine("</pap>");
dataToSend.AppendLine("--" + BOUNDARY);
dataToSend.AppendLine("Content-Encoding: binary");
dataToSend.AppendLine("Content-Type: text/html");
dataToSend.AppendLine("");
dataToSend.AppendLine(msg);
dataToSend.AppendLine("");
dataToSend.AppendLine("--" + BOUNDARY + "--");Stream requestStream = null;

string pushResult = "";
try
{
requestStream = HttpWReq.GetRequestStream();
}
catch (Exception ex)
{
pushResult = "Push failed! " + ex.ToString();
}
byte[] outStr = new ASCIIEncoding().GetBytes(dataToSend.ToString());
requestStream.Write(outStr, 0, outStr.Length);
requestStream.Close();

try
{
HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();
}
catch (Exception ex)
{
//push failed
}

if (HttpWRes != null)
{
HttpWRes.Close();
}

 

En esta linea requestStream = HttpWReq.GetRequestStream(); genera el siguiente error:

The remote server returned an error: (502) Bad Gateway.