Android的GCM丢失的注册C# [英] Android GCM Missing Registration C#
问题描述
我想实现使用谷歌GCM推送通知,但是,当我尝试将通知发送到GCM,我发现了 MissingRegistration
错误。
I'm trying to implement a push notification using the Google GCM, but, when I try to send a notification to GCM I'm getting the MissingRegistration
error.
我使用的是伪造的注册ID到目前为止,但我认为这有点像'注册没有找到在这种情况下提出的,对吧?
I'm using fake registration ids so far but I think that something like 'Registration not found' is raised in this case, right?
下面我的C#件code的
Here my C# piece of code
public static void send(List<String> clientRegistrationIds, GcmData data)
{
WebRequest request = WebRequest.Create(SEND_URL);
// Headers.
request.Method = POST;
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
request.Headers.Add(string.Format("Authorization: key={0}", API_KEY));
request.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
string postData = new JavaScriptSerializer().Serialize(new GcmRequest(clientRegistrationIds, data));
Console.WriteLine(postData);
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = request.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
Console.WriteLine(sResponseFromServer);
tReader.Close();
dataStream.Close();
tResponse.Close();
}
序列化POSTDATA变量:
The serialized postData variable:
{"registration_ids":["123"],"data":{"message":"New request!"}}
我的回答是:
Error=MissingRegistration
我在做什么错了?
What I'm doing wrong?
谢谢!
编辑:更改内容类型为应用程序/ JSON
工作。现在,我得到了我期待的错误: InvalidRegistration
。但应用程序/ x-WWW的形式urlen codeD;字符集= UTF-8
不应该是正确的内容类型
Changing the content-type to application/json
worked. Now i'm getting the error that I was expecting: InvalidRegistration
. BUT, application/x-www-form-urlencoded;charset=UTF-8
wasn't supposed to be the correct Content-Type?
推荐答案
改变了的ContentType为应用程序/ JSON
和它的工作。
Changed the ContentType to application/json
and it worked.
这篇关于Android的GCM丢失的注册C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!