【问题标题】:HTTP Status Code: 401 in GCMDemoHTTP 状态码:GCMDemo 中的 401
【发布时间】:2012-12-08 17:22:17
【问题描述】:

参考:http://developer.android.com/google/gcm/demo.html

尝试向我的 Android 设备发送消息时出现服务器 401。

HTTP Status 500 - HTTP Status Code: 401

type Exception report

message HTTP Status Code: 401

description The server encountered an internal error (HTTP Status Code: 401) that        prevented it from fulfilling this request.

exception

com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401
com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177)
com.google.android.gcm.server.Sender.send(Sender.java:121)
com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServ    let.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.29 logs.

谁能告诉我怎么解决?谢谢!

【问题讨论】:

  • 我通过在 Google 开发控制台中生成额外的服务器端 api 密钥来解决此问题。

标签: google-cloud-messaging http-status-code-401


【解决方案1】:

您应该查看 GCM 文档,其中解释了 GCM 响应:http://developer.android.com/google/gcm/gcm.html#response 并排除 401 错误代码:http://developer.android.com/google/gcm/gcm.html#auth_error

来自文档的描述:

身份验证错误 您尝试使用的发件人帐户 发送消息无法通过身份验证。可能的原因有:

授权标头丢失或语法无效。

作为密钥发送的项目编号无效。

密钥有效,但 GCM 服务已禁用。

请求来自未在服务器密钥 IP 中列入白名单的服务器。

所以我会检查以确保您正确设置了授权标头,并且您的 Google 项目编号已通过 GCM 正确设置并接受您的服务器 IP。

【讨论】:

  • 非常感谢!我只是验证了 Google 项目编号和接受我的服务器 IP 的 api-key。但仍然出现该错误...
  • 然后我会检查以确保在 Google 项目中启用了 GCM,并允许所有 IP 地址仅用于测试。
  • 谢谢您的回答!原因是您提到的api-key,当我更改api-key并允许所有IP地址时,消息发送没有任何错误!谢谢您帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-26
  • 1970-01-01
  • 1970-01-01
  • 2020-07-05
  • 2011-05-20
  • 2018-02-14
相关资源
最近更新 更多