curl基礎教程


curl語法: curl [options] <url> 

curl默認直接將http響應的body內容打印輸出(不打印http響應頭)

User-Agent默認為: curl/版本號 ,如:User-Agent: curl/7.65.3

http請求默認沒有Referer

默認使用HTTP/1.1

使用案例

1、發送GET請求,並打印輸出http響應的body內容

curl http://www.nyushukka.com/mysqltables.sql

2、發送HEAD請求,只打印輸出http響應頭

curl --head http://geotar.com/phpbb_db_backup_data.sql

3、使用HTTP/1.0協議

curl --http1.0 http://www.sogou.com/phpbb_db_backup_data.sql

4、跟隨302跳轉

curl --location http://www.sogou.com/

5、將http響應的body內容寫到文件中

curl --output test1.txt http://www.sogou.com/

6、設置Referer請求頭

curl --referer "http://www.so.com/" http://www.sogou.com/

7、發送http PUT請求,上傳test1.txt文件

curl --upload-file test1.txt http://www.sogou.com/

8、發送POST請求,不進行URL編碼,默認使用Content-Type: application/x-www-form-urlencoded

curl --data "username=admin&passwd=123456" http://www.sogou.com/

9、對post請求的數據進行URL編碼,"&"符號也會被編碼

curl --data-urlencode "username=admin&passwd=123456" http://www.sogou.com/

10、忽略https證書錯誤

curl --insecure https://frostyfactory.club/strandz.png

11、添加http請求頭

curl --header "Cookies: user=admin" http://www.baidu.com/strandz.png

12、請求ipv6地址

curl --ipv6 http://www.google.com/

13、post請求上傳文件,uploadFile是form表單的名字

curl -F "uploadFile=@test1.txt" http://www.baidu.com/

POST請求的形式像下面一樣:
/****
    POST / HTTP/1.1
    Host: www.so.com
    User-Agent: curl/7.65.3
    Accept: */*
    Content-Length: 269
    Content-Type: multipart/form-data; boundary=------------------------bf349de57ad4ce17

    --------------------------bf349de57ad4ce17
    Content-Disposition: form-data; name="uploadFile"; filename="test1.txt"
    Content-Type: text/plain

    <head><title>302 Found</ti
    <center><h1>302 Found</h1></center>
    <hr><cent
    --------------------------bf349de57ad4ce17--
****/




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM