HTTP状态代码:GCMDemo中的401 [英] HTTP Status Code: 401 in GCMDemo
问题描述
参考:http://developer.android.com/google/gcm/demo.html
尝试向我的android设备发送消息时的服务器401。
HTTP状态500 - HTTP状态码:401
类型例外报告
消息HTTP状态代码:401
描述服务器遇到内部错误(HTTP状态代码:401),导致无法完成此请求。
例外
com.google.android.gcm.server.InvalidRequestException:HTTP状态码: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 Apache Tomcat / 7.0.29日志中提供了根本原因的完整堆栈跟踪。
有人能告诉我如何解决吗?谢谢!
gcm.html#response> http://developer.android.com/google/gcm/gcm.html#response 并排查401错误代码: http://developer.android.com/google/gcm/gcm.html#auth_error
来自文档的描述:
身份验证错误
您尝试使用的发件人帐户
发送一条消息不能被认证。可能的原因有:
授权标题丢失或语法无效。
作为密钥发送的项目编号无效。
密钥有效,但禁用了GCM服务。
$ b 请求来源于未在服务器密钥IP列入白名单的服务器。
因此,我会检查以确保您正确设置了授权标头,并且您的Google项目编号已正确设置并使用GCM并接受了您的服务器IP。
Reference:http://developer.android.com/google/gcm/demo.html
Server 401 when trying to send a message to my android device.
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.
Could anybody tell me how to solve?Thank you!
You should take a look at the GCM docs where it explains the GCM response: http://developer.android.com/google/gcm/gcm.html#response and troubleshooting the 401 error code: http://developer.android.com/google/gcm/gcm.html#auth_error
Description from the docs:
Authentication Error The sender account that you're trying to use to send a message couldn't be authenticated. Possible causes are:
Authorization header missing or with invalid syntax.
Invalid project number sent as key.
Key valid but with GCM service disabled.
Request originated from a server not whitelisted in the Server Key IPs.
So I would check to make sure that you are setting you authorization header properly and that you Google Project number is properly setup with GCM and accepting your servers IP.
这篇关于HTTP状态代码:GCMDemo中的401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!