我正在尝试使用 C# Web 服务在黑莓中发送推送通知,但我面临的问题是它返回异常“远程服务器返回错误:(404)未找到。”。根据 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; }
问问题
809 次
1 回答
0
当我尝试上面的代码时,我得到了同样的错误。代替
String BESName = "cp****.pushapi.eval.blackberry.com";
和
String BESName = "cpxxx.pushapi.eval.blackberry.com/mss/PD_pushRequest";
并确保您在此处提供正确的用户名和密码:
HttpWReq.Credentials = new NetworkCredential("username", "password");
我得到了成功 = true;
然而,即使上面的代码执行成功,我仍然没有在黑莓设备上看到推送消息。
于 2013-02-05T11:07:27.200 回答