1. 程式人生 > 實用技巧 >Linux curl命令

Linux curl命令

在linux中curl是一個利用URL規則在命令列下工作的檔案傳輸工具,可以說是一款很強大的http命令列工具。它支援檔案的上傳和下載,是綜合傳輸工具,但按傳統,習慣稱url為下載工具,同時可以通過此命令驗證藉口。 

get請求

curl -X GET --header 'Accept: application/json' '需要請求url'

 注意:在除錯過程中 執行curl +請求url如果出現重定向錯誤,需要設定請求頭

post 請求

  

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json
' -d ''引數1':''' '請求的url'

curl命令常見引數

-A/--user-agent <string>              設定使用者代理髮送給伺服器
-b/--cookie <name=string/file>    cookie字串或檔案讀取位置
-c/--cookie-jar <file>                    操作結束後把cookie寫入到這個檔案中
-C/--continue-at <offset>            斷點續轉
-D/--dump-header <file>              把header資訊寫入到該檔案中
-e/--referer 來源網址 -f/--fail 連線失敗時不顯示http錯誤 -o/--output 把輸出寫到該檔案中 -O/--remote-name 把輸出寫到該檔案中,保留遠端檔案的檔名 -r/--range <range> 檢索來自HTTP/1.1或FTP伺服器位元組範圍 -s/--silent 靜音模式。不輸出任何東西
-T/--upload-file <file> 上傳檔案 -u/--user <user[:password]> 設定伺服器的使用者和密碼 -w/--write-out [format] 什麼輸出完成後 -x/--proxy <host[:port]> 在給定的埠上使用HTTP代理 -#/--progress-bar 進度條顯示當前的傳送狀態