9

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!

Nic
  • 113
  • 1
  • 1
  • 7

1 Answers1

14

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.

Community
  • 1
  • 1
selsine
  • 2,813
  • 2
  • 21
  • 22
  • Thank you so much!I just verify the Google Project number and the api-key which is accepting my server IP.But still got that error... – Nic Dec 24 '12 at 06:42
  • Then I would check to make sure that GCM is enabled in the Google Project, and allow all IP addresses just for a test. – selsine Dec 24 '12 at 15:30
  • 3
    Thank you for your answer!The reason is the api-key as you menthioned,when I changed the api-key and allowed all IP addresses,then messages were sent without any errors!Thank you for your help! – Nic Dec 25 '12 at 10:12