curl命令總結


 

在Linux中curl是一個利用URL規則在命令行下工作的文件傳輸工具,可以說是一款很強大的http命令行工具。它支持文件的上傳和下載,是綜合傳輸工具,但按傳統,習慣稱url為下載工具。

1、-x

-x, --proxy [PROTOCOL://]HOST[:PORT]  Use proxy on given port
     --proxy-anyauth  Pick "any" proxy authentication method (H)
     --proxy-basic   Use Basic authentication on the proxy (H)
     --proxy-digest  Use Digest authentication on the proxy (H)
     --proxy-negotiate  Use HTTP Negotiate (SPNEGO) authentication on the proxy (H)
     --proxy-ntlm    Use NTLM authentication on the proxy (H)
     --proxy-service-name NAME  SPNEGO proxy service name
     --service-name NAME  SPNEGO service name

-x/--proxy host[:port] 在給定的端口上使用HTTP代理

curl -x 127.0.0.1:端口 域名 #將域名解析到本機某個域名的某個端口

適用:適用於域名解析到負載均衡,后端某個服務器上執行測試。

 

2、-X

-X, --request COMMAND  Specify request command to use
     --resolve HOST:PORT:ADDRESS  Force resolve of HOST:PORT to ADDRESS
     --retry NUM   Retry request NUM times if transient problems occur
     --retry-delay SECONDS  Wait SECONDS between retries
     --retry-max-time SECONDS  Retry only within this period
     --sasl-ir       Enable initial response in SASL authentication

用法1:發送POST請求

curl -X POST -d 'post content' URL

 

注意:-d 選項后的內容強烈建議用單引號'包含起來,而非雙引號。

3、-L

 -L, --location      Follow redirects (H)
     --location-trusted  Like '--location', and send auth to other hosts (H)
     --login-options OPTIONS  Server login options (IMAP, POP3, SMTP)

 

用法1:curl -L ip.cn #查看服務器本機外網IP

用法2:自動跳轉

有的網址是自動跳轉的。使用 -L 參數,curl 就會跳轉到新的網址。

$ curl -L www.sina.com

 

 

4、-H -H/--header <header> 指定請求頭參數

 -H, --header LINE   Pass custom header LINE to server (H)

利用-H傳遞參數給服務器,如post請求時,傳遞Authorization給服務器

curl

 

5、-i

-i 參數可以顯示 http response 的頭信息,連同網頁代碼一起。-I 參數則只顯示 http response 的頭信息。

 

6、-v

-v/--verbose 小寫的v參數,用於打印更多信息,包括發送的請求信息,這在調試腳本是特別有用。

 

7、-d

-d/--data/--data-ascii <data> 指定POST的內容


免責聲明!

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



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