我在手机应用程序上实现了c2dm。 c2dm应用程序几天前确实收到了消息,但是在afterawhile它停止接收任何消息。
当推送到谷歌c2dm链接时,我得到了响应“id = 0:1325918022124320%6c25a09400000031”。标题好了,这里有什么不对吗?
我正在使用以下内容发送消息
public void SendMessage(string registrationId, string data, string sAuth)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://android.clients.google.com/c2dm/send");
request.Method = "POST";
request.KeepAlive = false;
NameValueCollection postFieldNameValue = new NameValueCollection();
postFieldNameValue.Add("registration_id", registrationId);
postFieldNameValue.Add("collapse_key", "1");
postFieldNameValue.Add("delay_while_idle", "0");
postFieldNameValue.Add("data.payload", data);
string postData = ConstructQueryString(postFieldNameValue);
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
request.ContentLength = byteArray.Length;
request.Headers.Add(HttpRequestHeader.Authorization, "GoogleLogin auth=" + sAuth);
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
HttpStatusCode responseCode = ((HttpWebResponse)response).StatusCode;
if (responseCode.Equals(HttpStatusCode.Unauthorized) || responseCode.Equals(HttpStatusCode.Forbidden))
{
Response.Write("Unauthorized - need new token");
}
else if (!responseCode.Equals(HttpStatusCode.OK))
{
Response.Write("Response from web service not OK :");
Response.Write(((HttpWebResponse)response).StatusDescription);
}
StreamReader reader = new StreamReader(response.GetResponseStream());
string responseLine = reader.ReadLine();
reader.Close();
Response.Write(responseLine);
}
答案 0 :(得分:1)
使用您的Google注册密钥检查两次。我认为它可能会以某种方式改变,因为你不能接受任何按摩。确保双方服务器和客户端上的密钥相同。