-A
-A參數(shù)指定客戶端的用戶代理標(biāo)頭,即User-Agent耍攘。
curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' https://google.com
也可以通過-H參數(shù)直接指定標(biāo)頭榕栏,更改User-Agent畔勤。
curl -H 'User-Agent: php/1.0' https://google.com
-b
-b參數(shù)用來向服務(wù)器發(fā)送cookie。
curl -b 'foo=bar;foo2=bar2' https://google.com
讀取本地文件cookies.txt臼膏,將其發(fā)送到服務(wù)器硼被。
curl -b cookies.txt https://google.com
-c
-c參數(shù)將服務(wù)器設(shè)置的cookie寫入一個(gè)文件。
curl -c cookies.txt https://google.com
-d
-d參數(shù)用于發(fā)送post請求的數(shù)據(jù)體渗磅。
curl -d 'login=emma&password=123' -X POST https://google.com/login
#或者
curl -d 'login=emma' -d 'password=123' -X POST https://google.com/login
使用-d參數(shù)嚷硫,HTTP請求會(huì)自動(dòng)加上標(biāo)頭Content-Type : application/x-www-form-urlencoded。并且會(huì)自動(dòng)將請求轉(zhuǎn)為post方法始鱼,因此可省略-X POST仔掸。
-d參數(shù)可以讀取本地文本文件的數(shù)據(jù),向服務(wù)器發(fā)送医清。
curl -d '@data.txt' https://google.com/login
--data-urlencode
--data-urlencode參數(shù)等同于-d起暮,發(fā)送post請求的數(shù)據(jù)體,區(qū)別在于會(huì)自動(dòng)將發(fā)送的數(shù)據(jù)進(jìn)行URL編碼会烙。
curl --data-urlencode 'comment=hello world' https://google.com/login
上面代碼中负懦,發(fā)送的數(shù)據(jù)hello world之間有一個(gè)空格,需要進(jìn)行URL編碼柏腻。
-e
-e參數(shù)用來設(shè)置HTTP的標(biāo)頭Referer纸厉,表示請求的來源。
curl -e 'https://google.com?q=example' https://www.example.com
-F
-F參數(shù)用來向服務(wù)器上傳二進(jìn)制文件五嫂。
curl -F 'file=@photo.png' https://google.com/profile
上面命令會(huì)給HTTP請求加上標(biāo)頭Content-Type: multipart/form-data颗品,然后將文件photo.png作為file字段上傳。-F參數(shù)可以指定MIME類型沃缘。
curl -F 'file=@photo.png;type=image/png' https://google.com/profile
上面命令指定MIME類型為image/png躯枢,否則curl會(huì)把MIME類型設(shè)為application/octet-stream。
-F參數(shù)也可以指定文件名槐臀。
curl -F 'file=@photo.png;filename=me.png' https://google.com/profile
上面命令中锄蹂,原始文件名為photo.png,但是服務(wù)器接收到的文件名為me.png水慨。
-G
-G參數(shù)用來構(gòu)造URL的查詢字符串败匹。
curl -G -d 'q=kitties' -d 'count=20' https://google.com/search
上面命令會(huì)發(fā)出一個(gè)get請求,實(shí)際請求的URL是https://google.com/search?q=kitties&count=20讥巡。如果省略-G掀亩,會(huì)發(fā)出一個(gè)post請求。
-H
-H參數(shù)添加HTTP請求的標(biāo)頭欢顷。
curl -H 'Accept-Language: en-US' https://google.com
curl -H 'Accept-Language: en-US' -H 'Secret-Message: xyzzy' https://google.com/login
curl -d '{"login": "emma", "pass": "123"}' -H 'Content-Type: application/json' https://google.com/login
-i
-i參數(shù)打印出服務(wù)器回應(yīng)的HTTP標(biāo)頭槽棍。
curl -i https://www.example.com
-I
-I參數(shù)向服務(wù)器發(fā)出head請求,然后將服務(wù)器返回的http標(biāo)頭打印出來。
curl -I https://www.example.com
上面命令輸出服務(wù)器對head請求的回應(yīng)炼七。
--head參數(shù)等同于-I缆巧。
curl --head https://www.example.com
-k
-k參數(shù)指定跳過SSL檢測。
curl -k https://www.example.com
-L
-L參數(shù)會(huì)讓http請求跟隨服務(wù)器的重定向豌拙。curl默認(rèn)不跟隨重定向陕悬。
curl -L -d 'tweet=hi' https://api.twitter.com/tweet
--limit-rate
--limit-rate用來限制http請求和回應(yīng)的帶寬,模擬慢網(wǎng)速的環(huán)境按傅。
curl --limit-rate 200k https://google.com
上面命令會(huì)將帶寬限制在每秒200k字節(jié)捉超。
-o
-o參數(shù)將服務(wù)器的回應(yīng)保存成文件,等同于wget命令唯绍。
curl -o example.html https://www.example.com
上面命令將www.example.com保存成example.html拼岳。
-O
-O參數(shù)將服務(wù)器回應(yīng)保存成文件,并將url的最后部分當(dāng)做文件名况芒。
curl -O https://www.example.com/foo/bar.html
上面命令將服務(wù)器回應(yīng)保存成文件惜纸,文件名為bar.html。
-s
-s參數(shù)將不輸出錯(cuò)誤和進(jìn)度信息绝骚。
curl -s https://www.example.com
-S
-S參數(shù)指定只輸出錯(cuò)誤信息耐版,通常與-s一起使用。
-u
-u參數(shù)用來設(shè)置服務(wù)器認(rèn)證的用戶名和密碼压汪。
curl -u 'bob:12345' https://google.com/login
上面命令設(shè)置用戶名為bob粪牲,密碼為12345,然后將其轉(zhuǎn)為http標(biāo)頭蛾魄。
-v
-v參數(shù)輸出通信的整個(gè)過程虑瀑,用于調(diào)試湿滓。
curl -v https://www.example.com
--trace參數(shù)也可用于調(diào)試滴须,還會(huì)輸出原始的二進(jìn)制數(shù)據(jù)。
curl --trace - https://www.example.com
-x
-x參數(shù)指定http請求的代理叽奥。
curl -x socks5://james:cats@myproxy.com:8080 https://www.example.com
-X
-X參數(shù)指定http請求的方法扔水。
curl -X POST https://www.example.com