
https://curl.se/docs/manpage.html
curl [options / URLs]仅做拓展,实际工作感觉不一定会用的上
http://site.{1,2,3}.com
等价于发了请求了三个 host
http://site.1.com
http://site.2.com
http://site.3.com类似 range(1,100)
ftp://ftp.example.com/file[1-100].txt文件 # 100个请求
ftp://ftp.example.com/file[001-100].txt(带0) # 100个请求
ftp://ftp.example.com/file[a-z].txt文件 # 26个请求注意:不支持嵌套序列,但可以在每个序列旁边使用多个嵌套序列
http://example.com/archive[1996-1999]/vol[1-4]/第{a,b,c}部分.htmlhttp://example.com/file[1-100:10].txt文件 # 每10个取一次,总共10个请求
http://example.com/file[a-z:2].txt文件 # 每2个取一次,总共13个请求https://www.cnblogs.com/poloyy/返回的是网页的 html 源码

后面的栗子,基本都会加 -v,是为了看请求的详细过程,更容易看到对应的参数已生效,实际使用不需要每次都 -v
--user-agent <name>
curl -v -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36" http://baidu.com
--cookie <data|file>
curl -v -b 'foo=bar' http://baidu.comRequest Headers 将会生成一个Cookie: foo=bar,向服务器发送一个名为 foo、值为 bar 的 Cookie

通过打印详细信息,可以看到请求头的确加了
--cookie-jar <filename>
curl -k -v -c test.txt https://www.baidu.com/s?wd=123%E8%89%BE%E5%BE%B7&rsv_spt=1&rsv_iqid=0xf0b9806f0000107b&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_dl=tb&rsv_sug3=6&rsv_sug1=2&rsv_sug7=100&rsv_sug2=0&rsv_btype=i&inputT=1138&rsv_sug4=1138会将百度响应需要设置的 Cookie 写入 test.txt 文件


--data <data>
curl -v -d 'wd=biying' -d 'ie=UTF-8' https://www.baidu.com/s
Content-Type : application/x-www-form-urlencoded
-X POST作用:参数等同于 -d,发送 POST 请求的数据体,但它会自动将发送的数据进行 URL 编码
curl -v -G --data-urlencode 'wd=b i y i n g' -d 'ie=UTF-8' https://www.baidu.com/s
会将空格进行 URL 编码
curl -v -G -d 'wd=b i y i n g' -d 'ie=UTF-8' https://www.baidu.com/s
-d 就不会 url 编码
作用:POST 请求体,可以接收一个完整的 json 字符串
curl --location --request POST 'http://test.com/account.login?ver=1.0&df=json&cver=3.7.8&os=android' \
--header 'Content-Type: application/json' \
--data-raw '{
"id":"123",
"service":"account.login",
"client":{
"ve":"3.7.8",
"os":"android",
"si":"123",
"ex":{
"brand":"vivo",
"dpfr":"8.1.0",
},
"empty":false
},
"data":{
"ex":{
"token":"123"
}
}
}'--referer <URL>
Referer,表示请求的来源curl -v -e "test" http://baidu.com
--form <name=content>
curl -F 'file=@photo.png' https://google.com/profile 自动给 HTTP Request Headers 加上 Content-Type: multipart/form-data ,然后将文件 photo.png 作为 file 字段的值上传
curl -F 'file=@photo.png;type=image/png' https://google.com/profile指定 MIME 类型为 image/png ,否则 curl 会把 MIME 类型设为 application/octet-stream
curl -F 'file=@photo.png;filename=me.png' https://google.com/profile服务器接收到的文件名为 me.png
--get
curl -v -G -d 'wd=biying' -d 'ie=UTF-8' https://www.baidu.com/s
本来 -d 会让 HTTP 请求变成 POST,但因为加了 -G,仍然是 GET,因为是查询字符串
--header <header/@file>
curl -v -H "token:123" -H "Content-type:application/json" http://baidu.com
-H 指定两个请求头字段,都加上了
--include
curl -i http://baidu.com
---head
curl -I http://baidu.com
--insecure
curl -k -I https://www.baidu.com
目测不加也能正常发起 HTTPS 的请求
--location
curl -L -d 'tweet=hi' https://api.twitter.com/tweet建议都加上
作用:限制 HTTP 请求和回应的带宽,模拟慢网速的环境
curl -v --limit-rate 2k http://baidu.com将带宽限制在每秒 2K 字节
但我测试了下,感觉比较鸡肋,还是瞬间完成请求
--output <file>
wget 命令curl -o baidu.html http://baidu.com
--remote-name

--silent

--show-error
curl -S -s https://google.com/login如果正确,则正常输出,如果错误则只输出错误信息,不输出运行结果
--user <user:password>
curl -u 'bob:12345' https://google.com/login--verbose
一路都是栗子,不再举栗子
作用:输出通信的整个过程,比 -v 更详细
不举栗子,因为是 16 进制的数据结果,直接看下面的 --trace-ascii,用法一样,输出的数据也一样,但是是用 10 进制显示
作用:输出通信的整个过程,比 -v 更详细,但没有十六进制输出,而是十进制
为了更全面的看到请求的整个通信链路,直接用了我工作上一个接口,但我把敏感信息都换了,所以是请求不通的哈
curl --trace-ascii - --location --request POST 'http://test.com/account.login?ver=1.0&df=json&cver=3.7.8&os=android' \
--header 'Content-Type: application/json' \
--data-raw '{
"id":"123",
"service":"account.login",
"client":{
"ve":"3.7.8",
"os":"android",
"fr":"API Level-27",
"gameId":"100000",
"channelId":"100000",
"si":"123",
"ex":{
"brand":"vivo",
"dpfr":"8.1.0",
"imei":"123",
"imsi":"123",
"mac":"123",
"mf":"vivo",
"mobile":"",
"model":"123",
"net":"wifi",
"orient":"P",
"packageName":"123",
"resX":"1080",
"resY":"2034",
"subChannelId":"",
"utdid":"123",
"versionCode":"1",
"versionName":"3.7.8"
},
"empty":false
},
"data":{
"ex":{
"token":"123"
}
}
}'

可以说非常详细了,连每个字段的字节大小都返回了
--write-out <format>
https://www.cnblogs.com/poloyy/p/14877100.html
--request <command>
curl -v -X POST http://baidu.com
curl -v --request POST http://baidu.com
不一定完全万能可用,根据自己需要进行修改
curl -L -S -s -K http://baidu.comcurl -L -S -s -K -X post \
-H "Content-type:application/json" \
-H ".." \
--data-raw "
{
"a":123,
"b:123
}"