使用 C# 为诺基亚 nid 推送通知
我正在努力从我的 C# 项目向诺基亚手机发送推送消息,并且我已经将所需的所有变量放入我的代码中,但我处理了错误 Bad Request,我不明白其原因。
这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
//notification ID string i will get i from OVI
notID = System.Web.HttpUtility.UrlEncode(notID);
string url = "https://alpha.one.ovi.com/nnapi/1.0/nid/" +(notID);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.Credentials = new NetworkCredential(ServiceId, service_secret);
request.ContentType = "application/x-www-form-urlencoded";
request_parameters = System.Web.HttpUtility.UrlEncode(request_parameters);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] buffer = encoding.GetBytes(request_parameters);
Stream newStream = request.GetRequestStream();
newStream.Write(buffer, 0, buffer.Length);
newStream.Close();
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream);
MessageBox.Show("response=========" + sr.ReadToEnd());
sr.Close();
resStream.Close();
}
else
{
MessageBox.Show("message====" + response.StatusCode);
}
}
}
i am working to sent a push message to Nokia phone from my c# project and i already put all the variables needed in my code but i handle an error Bad Request, i didn't understand its reason.
Here is my code:
private void button1_Click(object sender, EventArgs e)
{
//notification ID string i will get i from OVI
notID = System.Web.HttpUtility.UrlEncode(notID);
string url = "https://alpha.one.ovi.com/nnapi/1.0/nid/" +(notID);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.Credentials = new NetworkCredential(ServiceId, service_secret);
request.ContentType = "application/x-www-form-urlencoded";
request_parameters = System.Web.HttpUtility.UrlEncode(request_parameters);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] buffer = encoding.GetBytes(request_parameters);
Stream newStream = request.GetRequestStream();
newStream.Write(buffer, 0, buffer.Length);
newStream.Close();
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream);
MessageBox.Show("response=========" + sr.ReadToEnd());
sr.Close();
resStream.Close();
}
else
{
MessageBox.Show("message====" + response.StatusCode);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请检查以下项目: https://projects.forum.nokia.com/dotnet_notifications_api
它是诺基亚通知 API 的 .NET 包装器。
Please check the following project: https://projects.forum.nokia.com/dotnet_notifications_api
It is a .NET wrapper for the Nokia Notifications API.