【问题标题】:curl command is not executing push notification using pushercurl 命令未使用 pusher 执行推送通知
【发布时间】:2020-12-27 22:57:06
【问题描述】:

我正在使用 ESP32 开发 Android 应用程序。我想要一个系统,当我按下按钮(硬件按钮)时,它会向 android 应用程序发送通知。我已将数据连接到 firebase 并使用推送器发送通知。我的设备是集成的。但是,我无法执行推送通知 curl 命令。 当我执行 curl 命令时(我什至下载了 curl.exe 并设置了路径):

curl -H "Content-Type: application/json" \
 -H "Authorization: Bearer **Secret Key**" \
 -X POST "https://**Instance ID**.pushnotifications.pusher.com/publish_api/v1/instances/**Instance ID**/publishes" \
 -d '{"interests":["hello" ,"fcm":{"notification":{"title":"Hello", "body":"Hello, world!"}}}'

我在命令提示符中遇到错误,如下所示:

C:\Windows\system32>curl -H "Content-Type: application/json" \
curl: (6) Could not resolve host: \
C:\Windows\system32>     -H "Authorization: Bearer **Secret Key**" \
'-H' is not recognized as an internal or external command,
operable program or batch file.
C:\Windows\system32>     -X POST "https://**Instance ID**.pushnotifications.pusher.com/publish_api/v1/instances/**Instance ID**/publishes" \
'-X' is not recognized as an internal or external command,
operable program or batch file.
C:\Windows\system32>     -d '{"interests":["hello"],"fcm":{"notification":{"title":"Hello", "body":"Hello, world!"}}}'
'-d' is not recognized as an internal or external command,
operable program or batch file.

【问题讨论】:

    标签: android curl push-notification pusher


    【解决方案1】:

    整个块应该是一个命令,但您的命令行似乎一次执行一行。

    试试下面的,我应该作为单行命令运行

    curl -H "Content-Type: application/json" -H "Authorization: Bearer **Secret Key**"  -X POST "https://**InstanceID**.pushnotifications.pusher.com/publish_api/v1/instances/**Instance ID**/publishes" -d '{"interests":["hello" ,"fcm":{"notification": "title":"Hello", "body":"Hello, world!"}}}'
    

    【讨论】:

    • 您好,感谢您的回复。我按照您的要求进行了更改。它有效,但它再次显示一个我无法理解的新错误。错误是:{"error":"Bad Request","description":"Failed to read body as a JSON object"} curl: (3) URL 位置 6 的大括号不匹配: ,fcm:{notification:
    • 我从这个线程得到了错误解决。 stackoverflow.com/questions/60839567/…非常感谢您的帮助@doydoy
    • 没问题,感谢分享解决方案 - 这是一个有趣的发现!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-18
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 2018-06-27
    相关资源
    最近更新 更多