Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
Posted

1 solution

HTML
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900