curl post请求的几种方式

参数说明

格式: curl -H 请求头 -d 请求体 -X POST 接口地址

示例

1、application/x-www-form-urlencoded

$ curl  -d 'hello=world&test=123' -X POST http://localhost:3000/api/basic

2、application/json

$ curl  --header "Content-Type: application/json" -d '{"hello": "world"}'  -X POST http://localhost:3000/api/json 

还可以将请求体用文件保存
如json文件data.json

{
"hello":"world"
}

可以通过这样请求

$ curl  --header "Content-Type: application/json" -d @data.json  -X POST http://localhost:3000/api/json 

3、multipart/form-data

curl http://localhost:3000/api/multipart -F raw=@raw.data -F hello=world

4、当请求post报415时,如下图,则可能是header的参数问题,如不支持application/json,则用application/x-www-form-urlencoded
image

posted on 2022-07-08 18:42  每天进步一点点点点点  阅读(11760)  评论(0编辑  收藏  举报