黑莓推送通知投掷400错误请求 - 协议错误 [英] Blackberry Push Notifications throwing 400 Bad Request - Protocol Error

查看:97
本文介绍了黑莓推送通知投掷400错误请求 - 协议错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试使用BES的邮政服务向BlackBerry设备发送推送通知。



代码是这样的:



System.Net.WebRequest req = System.Net.WebRequest.Create(ConfigurationManager.AppSettings [BESURL] + userEmailID +

&PORT =+ ConfigurationManager.AppSettings [BBAPPID] +&REQUESTURI = /);



List<标题和GT;标题=新列表<标题>();

标题title =新标题();

title.title = sampleString;

标题。添加(标题);



string st = JsonConvert.SerializeObject(标题);



req.Method =POST;

req.ContentType =application / json;

byte [] sentData = Encoding.UTF8.GetBytes(st);

req.ContentLength = sentData.Length;

using(System.IO.Stream sendStream = req.GetRequestStream())

{

sendStream.Write(sentData,0,sentData.Length);

sendStream.Close();

}

System.Net.WebResponse res = req.GetResponse();



如果我使用具有相关有效负载的POSTMAN客户端发送相同请求,则可以正常工作。



有人可以帮忙吗?

解决方案

这似乎是发出POST请求的问题。我有同样的问题并解决了它如下

1)将WebRequest转换为HttpWebRequest
HttpWebRequest req =(HttpWebRequest)System.Net.WebRequest.Create(ConfigurationManager) .AppSettings [BESURL] + userEmailID +
& PORT =+ ConfigurationManager.AppSettings [BBAPPID] +& REQUESTURI = /);

2)使用凭据属性向请求发送凭据
req.Credentials = CredentialCache.DefaultCredentials;

3)将Expect100Continue标头设置为false
req.ServicePoint.Expect100Continue = false
有关此标头的更多信息:
http:/ /haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx

希望这能解决您的问题。


Hi,

I am trying to send a push notification to BlackBerry devices using the BES's post service.

The Code is something like this:

System.Net.WebRequest req = System.Net.WebRequest.Create(ConfigurationManager.AppSettings["BESURL"] + userEmailID +
"&PORT=" + ConfigurationManager.AppSettings["BBAPPID"] + "&REQUESTURI=/");

List<Titles> Titles = new List<Titles>();
Titles title = new Titles();
title.title = sampleString;
Titles.Add(title);

string st = JsonConvert.SerializeObject(Titles);

req.Method = "POST";
req.ContentType = "application/json";
byte[] sentData = Encoding.UTF8.GetBytes(st);
req.ContentLength = sentData.Length;
using (System.IO.Stream sendStream = req.GetRequestStream())
{
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
}
System.Net.WebResponse res = req.GetResponse();

If I send the Same Request using the POSTMAN client with relevant Payload, it works.

Can someone please help?

解决方案

This seems to be an issue with making POST request. I had the same problem and solved it as below

1) Convert WebRequest to HttpWebRequest
HttpWebRequest req = (HttpWebRequest)System.Net.WebRequest.Create(ConfigurationManager.AppSettings["BESURL"] + userEmailID +
 "&PORT=" + ConfigurationManager.AppSettings["BBAPPID"] + "&REQUESTURI=/");
  
2) Send credentials to the request using Credentials property
    req.Credentials = CredentialCache.DefaultCredentials;

3) Set Expect100Continue header to false
   req.ServicePoint.Expect100Continue = false
   More info about this header: 
   http://haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx

Hope this solves your issue.


这篇关于黑莓推送通知投掷400错误请求 - 协议错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆