[英]Firebase cloud messaging getting internal server error when calling “https://fcm.googleapis.com/fcm/send”
I wrote this code in spring boot(I am using Intellij IDE).In code androidFcmUrl= " https://fcm.googleapis.com/fcm/send ". 我在春季启动时编写了此代码(我正在使用Intellij IDE)。代码为androidFcmUrl =“ https://fcm.googleapis.com/fcm/send ”。 androidFcmKey=my server key.
androidFcmKey =我的服务器密钥。 deviceToken=device id.
deviceToken =设备ID。
@RequestMapping(value = "/pushNotification", method = RequestMethod.GET)
public void pushNotification() {
try {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type","application/json; UTF-8");
httpHeaders.set("Authorization", "key=" + androidFcmKey);
JSONObject msg = new JSONObject();
JSONObject json = new JSONObject();
msg.put("title", "Title");
msg.put("body", "Message");
msg.put("notificationType", "Test");
json.put("data", msg);
json.put("notification",msg);
json.put("to", deviceToken);
HttpEntity<String> httpEntity = new HttpEntity<>(json.toString(), httpHeaders);
String response = restTemplate.postForObject(androidFcmUrl, httpEntity, String.class);
System.out.println(response);
} catch (JSONException e) {
e.printStackTrace();
}
}
I am getting Status 500 internal server error. 我收到状态500内部服务器错误。
2018-11-28 17:42:47.712 ERROR 15292 --- [nio-8088-exec-2] oaccC[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; 2018-11-28 17:42:47.712错误15292-[nio-8088-exec-2] oaccC [。[。[/]。[dispatcherServlet]:Servlet [dispatcherServlet]的Servlet.service()路径[]引发异常[请求处理失败; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for " https://fcm.googleapis.com/fcm/send ": Connection timed out: connect;
嵌套的异常是org.springframework.web.client.ResourceAccessException:POST请求“ https://fcm.googleapis.com/fcm/send ”时发生I / O错误:连接超时:connect; nested exception is java.net.ConnectException: Connection timed out: connect] with root cause.
嵌套的异常是java.net.ConnectException:连接超时:具有根本原因的connect]。
But when I am hitting the api form postman with same payload I am getting a success response with message id. 但是,当我用相同的有效载荷击中api形式的邮递员时,我收到一条消息ID为成功的响应。
The androidFcmUrl
you are trying to call is might not reachable. 您尝试调用的
androidFcmUrl
可能无法访问。 Ensure the path is correct and is listening. 确保路径正确并且正在侦听。 Also ensure if there is any proxy interrupting your URL.
还请确保是否有任何代理服务器中断您的URL。
some time IDE having diff conf setting then tool which you are using like postman. 一段时间,IDE具有diff conf设置,然后使用的工具就像邮递员一样。 Its looks like issue of environment only.
它看起来仅是环境问题。 You can try to run app via OS console instead of IDE and you will see difference.
您可以尝试通过OS控制台而不是IDE来运行应用程序,您将看到区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.