下面是我得到的异常,即使我的服务器和浏览器应用程序的 API 密钥是有效的。我使用 curl 检查了它。我以 UTF-8 和 JSON 格式发送 GCM 请求。从外部公司网络对其进行测试。
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)
我可以知道这个的原因和解决方案吗?