尝试使用 C2DM 验证应用程序服务器时出现 403 禁止错误

发布于 2024-12-17 23:15:58 字数 1435 浏览 0 评论 0原文

我创建了一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吹泡泡o 2024-12-24 23:15:58

人们强烈推荐 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文