![](/img/trans.png)
[英]What is the Java equivalent to use https://fcm.googleapis.com/fcm/send REST Api
[英]Firebase cloud messaging getting internal server error when calling “https://fcm.googleapis.com/fcm/send”
我在春季启动时编写了此代码(我正在使用Intellij IDE)。代码为androidFcmUrl =“ https://fcm.googleapis.com/fcm/send ”。 androidFcmKey =我的服务器密钥。 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();
}
}
我收到状态500内部服务器错误。
2018-11-28 17:42:47.712错误15292-[nio-8088-exec-2] oaccC [。[。[/]。[dispatcherServlet]:Servlet [dispatcherServlet]的Servlet.service()路径[]引发异常[请求处理失败; 嵌套的异常是org.springframework.web.client.ResourceAccessException:POST请求“ https://fcm.googleapis.com/fcm/send ”时发生I / O错误:连接超时:connect; 嵌套的异常是java.net.ConnectException:连接超时:具有根本原因的connect]。
但是,当我用相同的有效载荷击中api形式的邮递员时,我收到一条消息ID为成功的响应。
您尝试调用的androidFcmUrl
可能无法访问。 确保路径正确并且正在侦听。 还请确保是否有任何代理服务器中断您的URL。
一段时间,IDE具有diff conf设置,然后使用的工具就像邮递员一样。 它看起来仅是环境问题。 您可以尝试通过OS控制台而不是IDE来运行应用程序,您将看到区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.