我正在尝试使用C#Web在黑莓中发送推送通知 服务,但我面临的问题是它返回异常“遥控器 服务器返回错误:(404)Not Found。“。所有信息都是正确的 根据RIM标准,请尽快帮助我。
[WebMethod]
public bool push(string notification)
{
bool success = true;
byte[] bytes = Encoding.ASCII.GetBytes("Hello");
Stream requestStream = null;
HttpWebResponse HttpWRes = null;
HttpWebRequest HttpWReq = null;
String BESName = "cp****.pushapi.eval.blackberry.com";
try
{
//http://<BESName>:<BESPort>/push?DESTINATTION=<PIN/EMAIL>&PORT=<PushPort>&REQUESTURI=/
// Build the URL to define our connection to the BES.
string httpURL = "https://" + BESName + "/push?DESTINATION=2B838E45&PORT=32721&REQUESTURI=/";
//make the connection
HttpWReq = (HttpWebRequest)WebRequest.Create(httpURL);
HttpWReq.Method = ("POST");
//add the headers nessecary for the push
HttpWReq.ContentType = "text/plain";
HttpWReq.ContentLength = bytes.Length;
// ******* Test this *******
HttpWReq.Headers.Add("X-Rim-Push-Id", "2B838E45" + "~" + DateTime.Now); //"~" +pushedMessage +
HttpWReq.Headers.Add("X-Rim-Push-Reliability", "application-preferred");
HttpWReq.Headers.Add("X-Rim-Push-NotifyURL", ("http://" + BESName + "2B838E45~Hello~" + DateTime.Now).Replace(" ", ""));
// *************************
HttpWReq.Credentials = new NetworkCredential("Username", "Password");
requestStream = HttpWReq.GetRequestStream();
//Write the data from the source
requestStream.Write(bytes, 0, bytes.Length);
//get the response
HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();
var pushStatus = HttpWRes.Headers["X-RIM-Push-Status"];
//if the MDS received the push parameters correctly it will either respond with okay or accepted
if (HttpWRes.StatusCode == HttpStatusCode.OK || HttpWRes.StatusCode == HttpStatusCode.Accepted)
{
success = true;
}
else
{
success = false;
}
//Close the streams
HttpWRes.Close();
requestStream.Close();
}
catch (System.Exception)
{
success = false;
}
return success;
}
答案 0 :(得分:0)
当我尝试上面的代码时,我遇到了同样的错误。取代
String BESName = "cp****.pushapi.eval.blackberry.com";
使用
String BESName = "cpxxx.pushapi.eval.blackberry.com/mss/PD_pushRequest";
并确保您在此处提供正确的用户名和密码:
HttpWReq.Credentials = new NetworkCredential("username", "password");
我成功=真;
但是,即使上述代码执行成功,我仍然看不到BlackBerry设备上的推送消息。