我正在从我的asp.net项目发送推送消息到android手机和 我已经把register_id放在我的代码中,但我处理错误缺少注册,我不明白其原因。C2DM错误= MissingRegistration我已经把registration_id请求
这里是我的代码:
public void SendMessage(string registrationId, string data, string sAuth)
{
string collapseKey = Guid.NewGuid().ToString("n");
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);
string url = "https://android.apis.google.com/c2dm/send?";
url = url + HttpUtility.UrlEncode("registration_id=" + registrationId + "&collapse_key=" + collapseKey + "&data.payload=" + data);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.Headers.Add("Authorization", "GoogleLogin auth=" + sAuth);
//request.ContentLength = 0;
string encoded = HttpUtility.UrlEncode(url);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] buffer = encoding.GetBytes(encoded);
Stream newStream = request.GetRequestStream();
newStream.Write(buffer, 0, buffer.Length);
newStream.Close();
//Reading return Response
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream);
string value = sr.ReadToEnd().ToString();
Label1.Text = value;
//Response.Write(sr.ReadToEnd());
sr.Close();
resStream.Close();
}
}
catch (Exception ex)
{
throw (ex);
}
}
我运行我的android应用程序,我处理registration_id,我试图发送推送消息这个ID,但我不能谷歌响应我“错误= MissingRegistration” –
你可以检查registrationId不是空?您可以尝试捕捉HTTP请求中使用的网址,检查是否包含注册ID值 – Hicham
我正在调试项目registrationId不为空,但已经谷歌回应我这个错误... –