[英]Android GCM Missing Registration C#
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. 我正在尝试使用Google GCM实施推送通知,但是,当我尝试向GCM发送通知时,出现MissingRegistration
错误。
I'm using fake registration ids so far but I think that something like 'Registration not found' is raised in this case, right? 到目前为止,我使用的是伪造的注册ID,但在这种情况下,我会提出类似“找不到注册”的信息,对吗?
Here my C# piece of code 这是我的C#代码段
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();
}
The serialized postData variable: 序列化的postData变量:
{"registration_ids":["123"],"data":{"message":"New request!"}}
My response: 我的回复:
Error=MissingRegistration
What I'm doing wrong? 我做错了什么?
Thanks! 谢谢!
EDIT: Changing the content-type to application/json
worked. 编辑:将内容类型更改为application/json
起作用。 Now i'm getting the error that I was expecting: InvalidRegistration
. 现在,我得到了我所期望的错误: InvalidRegistration
。 BUT, application/x-www-form-urlencoded;charset=UTF-8
wasn't supposed to be the correct Content-Type? 但是, application/x-www-form-urlencoded;charset=UTF-8
不应被认为是正确的Content-Type吗?
将ContentType更改为application/json
并起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.