Windows上curl使用

前言

Windows

CMD

Get请求

1
curl https://www.psvmc.cn/login.json

Post请求

1
curl -H "Content-Type: application/json" -X POST -d "{}" "https://schoolapi.xhkjedu.com/sexam/eb/gettime"

注意:

在Window中

  • 单引号要改成双引号
  • JSON格式数据中双引号要加\转义

带参数的请求

1
curl -v -H "Content-Type: application/json" -X POST -d "{\"username\":\"ycl\",\"password\":\"123456\"}" "https://zyapitest.xhaiedu.com/web/auth/login"

PowerShell

在 PowerShell 中,加上 .exe 后缀,强制使用 Windows 自带的 curl 工具

在 PowerShell 中,双引号字符串内要表示一个 ",需要用两个双引号 "" 转义

直接用 单引号包裹整个 JSON也不行:

1
curl.exe -H "Content-Type: application/json" -X POST -d "{""username"":""ycl"",""password"":""123456""}" "https://zyapitest.xhaiedu.com/web/auth/login"