简体   繁体   English

调用“ https://fcm.googleapis.com/fcm/send”时,Firebase云消息传递出现内部服务器错误

[英]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.

相关问题 什么是相当于使用 https://fcm.googleapis.com/fcm/send REST Api 的 Java - What is the Java equivalent to use https://fcm.googleapis.com/fcm/send REST Api Firebase Cloud Messaging(FCM)无法获取数据 - Firebase Cloud Messaging (FCM) not getting data MismatchSenderId错误Firebase云消息传递(FCM) - MismatchSenderId error Firebase Cloud Messaging (FCM) 如何向FCM(Firebase云消息传递)令牌的特定用户发送消息? - How to send a message to a specific user of an FCM (Firebase Cloud Messaging) token? addCompleteListener()尚未解决-Firebase Cloud Messaging(FCM) - addCompleteListener() is not being resolved - Firebase Cloud Messaging (FCM) 在Firebase Cloud Messaging上检查新通知。 (FCM) - Check for new notifications on Firebase Cloud Messaging. (FCM) 如何在我的应用从 Play 商店中删除之前修复暴露的 Firebase 云消息 (FCM) 服务器密钥? - How to fix exposed Firebase Cloud Messaging (FCM) server keys before my app gets removed from Play Store? FCM Cloud Messaging 与 Notifications 和 Message 的区别 - FCM Cloud Messaging difference from Notifications and Message 我无法在我的 android 仿真器中接收 Firebase 云消息传递 FCM - I Can' t receive the Firebase Cloud Messaging FCM In my android emulator 是否可以在没有 Firebase Cloud Messaging (FCM) 的情况下向所有安装了我的应用程序的设备发送推送通知? - is it possible to make push notifications to all devices which had installed my application without Firebase Cloud Messaging (FCM)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM