在curl命令上无法将主体作为JSON对象读取

问题描述 投票:1回答:1

我正在测试iOS开发的推送通知,目前正在使用Pusher。当我在终端中运行此命令时

curl -H "Content-Type:application/json"     -H "Authorization: Bearer 7FF3763C208E26F2198CE44624E9486B1EC8B02A489DCF2F476FD511763887AE" -X POST 'https://d3ca6e4b-3222-49c9-8028-f9c2d28b3ad7.pushnotifications.pusher.com/publish_api/v1/instances/d3ca6e4b-3222-49c9-8028-f9c2d28b3ad7/publishes' [email protected]

它给我这个警告

Warning: Couldn't read data from file "publish-body.json", this makes an empty 
Warning: POST.
{"error":"Bad Request","description":"Failed to read body as a JSON 
object"}

这是我的JSON文件

{
  "interests": [
    "Reminder"
  ],
  "apns": {
    "aps": {
      "alert": {
        "title": "Hello",
        "body": "Hello, world!"
       }
    }
  }
}

我尝试使用Pusher API,它告诉我的所有错误是由于错误的请求所致。有想法该怎么解决这个吗?这个程序是送给我女朋友的礼物,我很想让这个工作!

json curl pusher
1个回答
0
投票

这对我有用。确保您在publish_body.json文件所在的目录中,或者在curl命令中传递完整路径。

curl -H "Content-Type: application/json" -H "Authorization: Bearer 754C51611#################"      -X POST "https://59d4fe56-8e04-42c0-a456-f5e3373f850e.pushnotifications.pusher.com/publish_api/v1/instances/59d4fe34-8e04-43c0-a456-f5e3373f850e/publishes" -d @publish-body.json
© www.soinside.com 2019 - 2024. All rights reserved.