curl设置header和表单数据

老是分不清楚header和表单时的写法,每次都去翻别人的博客

从浏览器中获取某个请求的curl版本

在这里插入图片描述
下面是几种上述方法拷贝出来的curl命令参数,特意列出来,供参考一下。

设置header与表单

GET请求

1
2
3
4
5
6
7
8
9
10
curl 'http://xxxxxxxxx/vehicles?page=1&size=20&number=8' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Accept-Language: zh,en;q=0.9,ja;q=0.8,zh-TW;q=0.7,fr;q=0.6,zh-CN;q=0.5' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Referer: http://xxxxxxxxx/' \
-H 'userId: 454' \
-H 'Connection: keep-alive' \
-H 'token: af0d8773933eaeffc81d97924bd2a8fc' \
--compressed

POST请求,发送body信息
--data-binary DATA HTTP POST binary data (H)

1
2
3
4
5
6
7
8
9
10
11
12
13
curl 'http://xxxxxxxxx/nemt/nemt/order/cancel' 
-H 'Origin: http://xxxxxxxxx'
-H 'Accept-Encoding: gzip, deflate'
-H 'Accept-Language: zh,en;q=0.9,ja;q=0.8,zh-TW;q=0.7,fr;q=0.6,zh-CN;q=0.5'
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36'
-H 'Content-Type: application/json'
-H 'Accept: application/json, text/plain, */*'
-H 'Referer: http://xxxxxxxxx/'
-H 'userId: 454'
-H 'Connection: keep-alive'
-H 'token: af0d8773933eaeffc81d97924bd2a8fc'
--data-binary '{"id":"10076","reasonId":0}'
--compressed

POST请求,发送表单
--data DATA HTTP POST data (H)

1
2
# 此例来自:http://www.ruanyifeng.com/blog/2011/09/curl.html
curl -X POST --data "data=xxx" example.com/form.cgi

文件上传

1
2
3
4
5
6
# 此例来自项目中某安卓端代码
do_upload(){
curl -X POST -F "file=@$1" $2
}
# 此例来自:http://www.ruanyifeng.com/blog/2011/09/curl.html
curl --form upload=@localfilename --form press=OK [URL]

OK,清理书签完毕!

curl设置header和表单数据

https://eucham.me/2019/03/22/2a22ce9bac07.html

作者

遇寻

发布于

2019-03-22

更新于

2021-02-09

许可协议

评论