Google GCM中的HTTP响应代码401 [英] HTTP response code 401 in Google GCM
问题描述
即使我的服务器和浏览器应用程序的API密钥有效,以下是我所遇到的异常。我用卷曲检查了它。我以格式UTF-8和JSON发送GCM请求。从外部公司网络进行测试。
java.io.IOException:服务器返回的HTTP响应代码:401代表URL:https:/ /android.googleapis.com/gcm/send
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at sun.net.www.protocol.http。 HttpURLConnection $ 6.run(HttpURLConnection.java:1345)$ b $在java.security.AccessController.doPrivileged(本地方法)
在sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java: 1339)
在sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:993)
在java.net.URLConnection.getCont ent(URLConnection.java:688)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getContent(HttpsURLConnectionImpl.java:406)
at gcm1.MessageUtil.sendMessage(MessageUtil.java:58)
我可以知道原因和解决方案吗?
以下是使用GCM时出现401错误的可能原因:
您尝试使用的发件人帐户用于发送消息无法验证。可能的原因是:
$ b $ ul
检查您在授权标头中发送的令牌是否与您的项目相关的API密钥正确。
资料来源: https://developers.google。 com / cloud-messaging / http-server-ref#error-codes
Below is the exception I am getting even though my API key for server and browser application are valid. I checked it using curl. I send GCM request in both format UTF-8 and JSON. Testing it from outside corporate network.
java.io.IOException: Server returned HTTP response code: 401 for URL: https://android.googleapis.com/gcm/send
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1345)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1339)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:993)
at java.net.URLConnection.getContent(URLConnection.java:688)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getContent(HttpsURLConnectionImpl.java:406)
at gcm1.MessageUtil.sendMessage(MessageUtil.java:58)
May I know the reason and solution for this ?
Here are the possible causes for 401 error when using GCM:
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 ID sent as key.
- Key valid but with GCM service disabled.
- Request originated from a server not whitelisted in the Server Key IPs.
Check that the token you're sending inside the Authorization header is the correct API key associated with your project.
Source: https://developers.google.com/cloud-messaging/http-server-ref#error-codes
这篇关于Google GCM中的HTTP响应代码401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!