Windows的curl命令语法 [英] curl command syntax for windows

查看:73
本文介绍了Windows的curl命令语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下命令,该命令在Linux上效果很好,但在Windows上效果不佳.我找不到Windows的curl语法的任何文档.我尝试了引号..但仍然无法正常工作.谁能帮我这个命令,以便我可以在Windows上使用它(我已经在c驱动器中安装了curl.exe)

I have the following command which works well on Linux, but not on windows. I am not able to find any doc for curl syntax for windows. I experimented with the quotes .. but still not working. Can anyone help me with this command so that I can use it on Windows ( I have installed curl.exe in c drive)

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."]}}]}

推荐答案

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

Windows requires a ^ at the end of each line, double-quotes instead of single-quotes (except within json brackets), and within the json data, all the double-quotes must be escaped.

这是在Win10和WinXP命令提示符下工作的GET和POST的示例:

Here is an example of a GET and a POST that work on Win10 and WinXP command prompt:

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" ^

这篇关于Windows的curl命令语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆