curl
curl 請求參數詳解
curl 是一個功能強大的命令行工具,用于傳輸數據,支持多種協議(HTTP、HTTPS、FTP等)。它提供了大量參數來定制請求。以下是 curl 請求的主要參數分類和詳細介紹:
基本請求參數
-
-X/--request [METHOD]
-
指定HTTP請求方法(GET, POST, PUT, DELETE等)
-
示例:
curl -X POST https://example.com
-
-
-d/--data [DATA]
-
發送POST請求的數據
-
示例:
curl -d "name=John&age=30" https://example.com
-
-
-G/--get
-
將-d參數的數據以GET方式附加到URL后
-
示例:
curl -G -d "q=test" https://example.com/search
-
-
-H/--header [HEADER]
-
添加HTTP頭
-
示例:
curl -H "Content-Type: application/json" https://example.com
-
認證參數
-
-u/--user [USER:PASSWORD]
-
設置服務器用戶和密碼
-
示例:
curl -u username:password https://example.com
-
-
--basic
-
強制使用HTTP Basic認證
-
示例:
curl --basic -u user:pass https://example.com
-
-
--digest
-
使用HTTP Digest認證
-
示例:
curl --digest -u user:pass https://example.com
-
數據傳輸參數
-
-F/--form [NAME=CONTENT]
-
模擬表單提交,可上傳文件
-
示例:
curl -F "file=@photo.jpg" https://example.com/upload
-
-
--data-urlencode [DATA]
-
URL編碼的POST數據
-
示例:
curl --data-urlencode "name=John Doe" https://example.com
-
-
-T/--upload-file [FILE]
-
上傳文件
-
示例:
curl -T localfile https://example.com/upload
-
輸出控制參數
-
-i/--include
-
在輸出中包含HTTP響應頭
-
示例:
curl -i https://example.com
-
-
-I/--head
-
只獲取HTTP頭信息
-
示例:
curl -I https://example.com
-
-
-o/--output [FILE]
-
將輸出寫入文件
-
示例:
curl -o output.html https://example.com
-
-
-O/--remote-name
-
使用遠程文件名保存輸出
-
示例:
curl -O https://example.com/file.txt
-
-
-s/--silent
-
靜默模式,不顯示進度和錯誤信息
-
示例:
curl -s https://example.com
-
-
-v/--verbose
-
顯示詳細操作信息
-
示例:
curl -v https://example.com
-
連接參數
-
--connect-timeout [SECONDS]
-
設置連接超時時間
-
示例:
curl --connect-timeout 10 https://example.com
-
-
-m/--max-time [SECONDS]
-
設置整個操作的最大時間
-
示例:
curl -m 30 https://example.com
-
-
--retry [NUM]
-
失敗重試次數
-
示例:
curl --retry 3 https://example.com
-
-
--retry-delay [SECONDS]
-
設置重試間隔時間
-
示例:
curl --retry 3 --retry-delay 5 https://example.com
-
代理參數
-
-x/--proxy [PROTOCOL://HOST:PORT]
-
使用代理服務器
-
示例:
curl -x http://proxy.example.com:8080 https://example.com
-
-
--proxy-user [USER:PASSWORD]
-
設置代理用戶名和密碼
-
示例:
curl --proxy-user user:pass -x http://proxy.example.com https://example.com
-
安全參數
-
-k/--insecure
-
允許不安全的SSL連接(不驗證證書)
-
示例:
curl -k https://example.com
-
-
--cacert [FILE]
-
指定CA證書文件
-
示例:
curl --cacert /path/to/cert.pem https://example.com
-
-
--cert [CERTIFICATE]
-
指定客戶端證書
-
示例:
curl --cert client.pem https://example.com
-
-
--key [KEY]
-
指定私鑰文件
-
示例:
curl --key key.pem https://example.com
-
Cookie處理
-
-b/--cookie [NAME=DATA]
-
發送Cookie
-
示例:
curl -b "session=1234" https://example.com
-
-
-c/--cookie-jar [FILE]
-
將服務器返回的Cookie保存到文件
-
示例:
curl -c cookies.txt https://example.com
-
-
-j/--junk-session-cookies
-
忽略會話Cookie
-
示例:
curl -j -b cookies.txt https://example.com
-
其他實用參數
-
-L/--location
-
跟隨重定向
-
示例:
curl -L https://example.com
-
-
--compressed
-
請求壓縮響應
-
示例:
curl --compressed https://example.com
-
-
-e/--referer [URL]
-
設置Referer頭
-
示例:
curl -e "https://google.com" https://example.com
-
-
-A/--user-agent [NAME]
-
設置User-Agent
-
示例:
curl -A "Mozilla/5.0" https://example.com
-
-
--limit-rate [RATE]
-
限制傳輸速度
-
示例:
curl --limit-rate 100K https://example.com/file
-
-
-C/--continue-at [OFFSET]
-
斷點續傳
-
示例:
curl -C - -O https://example.com/bigfile
-
高級參數
-
--resolve [HOST:PORT:ADDRESS]
-
自定義DNS解析
-
示例:
curl --resolve example.com:443:1.2.3.4 https://example.com
-
-
--request-target [PATH]
-
指定請求目標(原始請求行)
-
示例:
curl --request-target "*" -X OPTIONS http://example.com
-
-
--trace [FILE]
-
將調試信息寫入文件
-
示例:
curl --trace trace.txt https://example.com
-
-
--trace-ascii [FILE]
-
類似--trace,但使用ASCII格式
-
示例:
curl --trace-ascii trace.txt https://example.com
-
-
--raw
-
禁用所有內部HTTP解碼
-
示例:
curl --raw https://example.com
-
curl 的參數非常豐富,上述只是常用的一部分。要查看完整參數列表,可以運行 curl --help all 或訪問 curl 的官方文檔。
浙公網安備 33010602011771號