尝试使用 C2DM 验证应用程序服务器时出现 403 禁止错误
我创建了一个简单的 Web 应用程序并将其托管在本地服务器(本地主机)上,并使用以下代码获取身份验证 ID,但它返回 403 错误。还有没有什么方法可以在没有应用程序服务器的情况下向 C2DM 发送消息(我的意思是从桌面应用程序)?
这是我获取身份验证密钥的代码:
string GetToken()
{
HttpWebResponse response = null;
try
{
StringBuilder builder = new StringBuilder();
builder.Append("Email=").Append("MyGmailEmailAddress");
builder.Append("&Passwd=").Append("MyPassword");
builder.Append("&accountType=GOOGLE");
builder.Append("&source=PingMe");
builder.Append("&service=ac2dm");
byte[] bytes = Encoding.UTF8.GetBytes(builder.ToString());
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.google.com/accounts/ClientLogin");
request.Method = "POST";
request.ContentType ="application/x-www-form-urlencoded";
request.ContentLength = bytes.Length;
Stream stream = request.GetRequestStream();
stream.Write(bytes,0,bytes.Length);
stream.Close();
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
return reader.ReadToEnd();
}
catch (Exception ex)
{
return ex.Message;
}
finally
{
if(response != null)
response.Close();
}
}
I created a simple web application and hosted it on local server (local host) and used the below code to get the authentication id, but it return 403 error. also is there any way to send message to C2DM without application server I mean from desktop application?
here is my code to get authentication key:
string GetToken()
{
HttpWebResponse response = null;
try
{
StringBuilder builder = new StringBuilder();
builder.Append("Email=").Append("MyGmailEmailAddress");
builder.Append("&Passwd=").Append("MyPassword");
builder.Append("&accountType=GOOGLE");
builder.Append("&source=PingMe");
builder.Append("&service=ac2dm");
byte[] bytes = Encoding.UTF8.GetBytes(builder.ToString());
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.google.com/accounts/ClientLogin");
request.Method = "POST";
request.ContentType ="application/x-www-form-urlencoded";
request.ContentLength = bytes.Length;
Stream stream = request.GetRequestStream();
stream.Write(bytes,0,bytes.Length);
stream.Close();
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
return reader.ReadToEnd();
}
catch (Exception ex)
{
return ex.Message;
}
finally
{
if(response != null)
response.Close();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
人们强烈推荐 C2DM 专用的 Google 帐户。不要使用常规的 GMail。
另外,您是否已在 http://code.google.com/android/c2dm/ 上注册注册.html ?如果是,请尝试使用同一 Google 帐户再次注册。该网站是出了名的不稳定。
People are strongly recommending a dedicated Google account for C2DM. Don't use your regular GMail.
Also, have you signed up at http://code.google.com/android/c2dm/signup.html ? If yes, try signing up again, with the same Google account. That site is notoriously wonky.