问题描述
我已经创建了一个Android应用程序,即注册到谷歌C2DM服务。和它的成功正从C2DM服务registration_id令牌。
I have created an android app, that registering to google c2dm service. And It's getting a registration_id token from c2dm services successfully.
我已经签署了Android云端到设备消息的形式和我从C2DM服务收到确认电子邮件。
I already signed Android Cloud to Device Messaging form and I received confirmation email from c2dm service.
一切似乎都在客户端确定,它在仿真环境中得到registration_id。所以,它的确定。
Everything seems ok in client side, it's getting registration_id in simulator environment. So, it's ok.
不过,在服务器端,这是谷歌认证服务,它接收验证code,那么它的调用来C2DM与发送URL低于code。
But, On server side, It's authenticating google service, it's receiving Auth code then it's invoking to c2dm send url with below code.
public void SendMessage(string registrationId, string data)
{
ServicePointManager.ServerCertificateValidationCallback += delegate(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
};
string collapseKey = Guid.NewGuid().ToString("n");
string url = "https://android.apis.google.com/c2dm/send";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.Headers.Add("Authorization", "GoogleLogin auth=DQAAAKYAAACE_0NqG8Sj5lBf4YSPXs_ltQbTzPsAL5u1Q1KGF...");
string px = "registration_id=" + registrationId + "&collapse_key=" + collapseKey + "&data.payload=" + data;
string encoded = HttpUtility.UrlEncode(px);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] buffer = encoding.GetBytes(encoded);
Stream newStream = request.GetRequestStream();
newStream.Write(buffer, 0, buffer.Length);
newStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if(response.StatusCode == HttpStatusCode.OK)
{
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream);
Console.Write(sr.ReadToEnd());
sr.Close();
resStream.Close();
}
Console.WriteLine();
Console.ReadLine();
}
从C2DM服务
它仍然接收错误= InvalidRegistration
响应。
It's still receiving Error=InvalidRegistration
response from c2dm service.
我在做什么错?
推荐答案
好吧,它解决了。
我删除 HttpUtility.UrlEn code(PX);
和一切工作如我所料
Ok, It solved.I removed HttpUtility.UrlEncode(px);
and everything worked as I expected.
这篇关于Android的C2DM Invalidregistration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!