POST Curl 请求缺少正文

时间:2021-01-04 20:36:25

标签: php curl terminal paypal zsh

我正在尝试执行以下操作

 curl -v -X POST https://api-m.sandbox.paypal.com/v1/catalogs/products \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer Token" \
  -H "PayPal-Request-Id: ID" \ 
-d '{
  "name": "name",
  "description": "desc",
  "type": "SERVICE",
  "category": "SOFTWARE",
  "image_url": "website/image",
  "home_url": "website"
}'

它回吐以下错误:

{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"3d62fa9fd7b05","details":[{"location":"body","issue":"MISSING_REQUEST_BODY","description":"Request body is missing."}],"links":[{"href":"https://developer.paypal.com/docs/api/v1/billing/subscriptions#INVALID_REQUEST","rel":"information_link","method":"GET"}]}* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Could not resolve host: Optional
* Closing connection 1
curl: (6) Could not resolve host: Optional
* Could not resolve host: and
* Closing connection 2
curl: (6) Could not resolve host: and
* Could not resolve host: if
* Closing connection 3
curl: (6) Could not resolve host: if
* Could not resolve host: passed,
* Closing connection 4
curl: (6) Could not resolve host: passed,
* Could not resolve host: helps
* Closing connection 5
curl: (6) Could not resolve host: helps
* Could not resolve host: identify
* Closing connection 6
curl: (6) Could not resolve host: identify
* Could not resolve host: idempotent
* Closing connection 7
curl: (6) Could not resolve host: idempotent
* Could not resolve host: requests
* Closing connection 8
curl: (6) Could not resolve host: requests
zsh: command not found: -d

附言调试 ID 不起作用,链接有时会贬值并重定向到无用的内容。

谢谢!

1 个答案:

答案 0 :(得分:1)

查看您的输出,您使用的命令行似乎与您发布的命令行不同,因为输出包含来自 PayPal 示例中评论的文本,即:Optional and if passed, helps identify idempotent requests

PayPal 文档包含以下示例:

curl -v -X POST https://api-m.sandbox.paypal.com/v1/catalogs/products \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <Access-Token>" \
  -H "PayPal-Request-Id: <merchant-generated-ID>" \ // Optional and if passed, helps identify idempotent requests
-d '{
  "name": "Video Streaming Service",
  "description": "Video streaming service",
  "type": "SERVICE",
  "category": "SOFTWARE",
  "image_url": "https://example.com/streaming.jpg",
  "home_url": "https://example.com/home"
}'

当我执行示例时,相关输出为:

* Connection #0 to host api-m.sandbox.paypal.com left intact
{"error":"invalid_token","error_description":"Token signature verification failed"}* Could not resolve host:  
* Closing connection 1
curl: (6) Could not resolve host:  
* Rebuilt URL to: Optional/
* Could not resolve host: Optional
* Closing connection 2
curl: (6) Could not resolve host: Optional
* Rebuilt URL to: and/
*   Trying 192.168.200.167...
* TCP_NODELAY set

这看起来与您的输出相似。删除评论。此外,请务必删除 \ 之后的空格以避免 command not found: -d - 空格会导致 shell 假定下一行代表一个新命令。