用于Windows的curl命令语法

时间:2016-09-08 18:02:49

标签: windows curl

我有以下命令在Linux上运行良好,但在Windows上运行不正常。我无法找到任何关于Windows的curl语法的文档。我试验了引号..但仍然无法正常工作。任何人都可以帮我这个命令,以便我可以在Windows上使用它(我在c盘中安装了curl.exe)

curl -X POST -H "Content-Type: application/json" -H "X-Cachet-Token: secret" http://somegoodserver/api/v1/incidents -d '{"name":"Test","message":"Test message","status":"1"}'

我得到的错误是:

"status":400,"title":"Bad Request","detail":"The request cannot be fulfilled due to bad syntax.","meta": {"details":["The name format is invalid.","The status format is invalid.","The message format is invalid."]}}]}

1 个答案:

答案 0 :(得分:2)

Windows在每行的末尾需要^,双引号而不是单引号(json括号内除外),并且在json数据中,所有双引号都必须进行转义。

以下是适用于Win10和WinXP命令提示符的GET和POST的示例:

curl -X GET ^
-H "authorization: Basic [your authentication string, if needed]" ^
-H "cache-control: no-cache" ^
-H "content-type: application/json" ^
-H "x-forte-auth-organization-id: org_333251" ^
"https://sandbox.forte.net/api/v3/organizations/org_333251/locations/loc_191620/customers/"


curl -X POST ^
-H "authorization: Basic [your authentication string, if needed]" ^
-H "cache-control: no-cache" ^
-H "content-type: application/json" ^
-H "x-forte-auth-organization-id: org_333251" ^
-d "{ \"action\": \"sale\", \"authorization_amount\": 16.99, \"billing_address\": { \"first_name\": \"Paul\", \"last_name\": \"Hurst\" }, \"card\": { \"card_type\": \"visa\", \"name_on_card\": \"Forte James\", \"account_number\": \"4111111111111111\", \"expire_month\": \"12\", \"expire_year\": \"2020\", \"card_verification_value\": \"123\" } }" ^
"https://sandbox.forte.net/api/v3/organizations/org_333251/locations/loc_191620/transactions" ^