cURL 速查表
可搜尋、可列印的 curl 參考手冊——HTTP 方法、標頭、資料與表單、驗證、下載、cookie、TLS、代理以及除錯。免費。
基礎
12curl https://api.example.com
送出 GET 請求並印出主體
curl -o page.html https://example.com
將回應儲存到指定檔案
curl -O https://example.com/file.zip
以遠端檔名儲存
curl -i https://example.com
顯示回應標頭及主體
curl -I https://example.com
僅抓取回應標頭 (HEAD)
curl -v https://example.com
詳細輸出請求/回應
curl -s https://example.com
靜默模式,隱藏進度與錯誤
curl -sS https://example.com
靜默但仍顯示錯誤
curl -L https://example.com
跟隨 HTTP 重新導向 (3xx)
curl https://a.com https://b.com
一次請求多個網址
curl 'https://x.com/p?[1-5]'
用數字範圍迴圈處理網址
curl --version
印出 curl 版本與功能
HTTP 方法
9curl -X GET https://api.example.com
明確送出 GET 請求
curl -X POST https://api.example.com
送出 POST 請求
curl -X PUT https://api.example.com/1
送出 PUT 請求以取代資源
curl -X PATCH https://api.example.com/1
送出 PATCH 請求以更新欄位
curl -X DELETE https://api.example.com/1
送出 DELETE 請求
curl -I https://api.example.com
送出 HEAD 請求僅取標頭
curl -X OPTIONS https://api.example.com
送出 OPTIONS 預檢請求
curl --head https://api.example.com
HEAD 請求 -I 的長格式
curl --request POST https://x.com
設定方法 -X 的長格式
標頭
10curl -H 'Accept: application/json' https://x.com
新增單一請求標頭
curl -H 'X-Token: abc' -H 'X-Env: dev' https://x.com
新增多個標頭
curl -H 'Content-Type: application/json' https://x.com
宣告請求主體的內容類型
curl -H 'Authorization: Bearer TOKEN' https://x.com
送出 bearer 授權標頭
curl -H 'Host: example.com' https://1.2.3.4
覆寫 Host 標頭
curl -H 'Accept-Encoding: gzip' https://x.com
請求 gzip 壓縮的回應
curl -A 'MyAgent/1.0' https://x.com
設定 User-Agent 字串
curl -e 'https://ref.com' https://x.com
設定 Referer 標頭
curl -H 'X-Debug:' https://x.com
留空以移除預設標頭
curl --compressed https://x.com
請求並自動解壓回應
傳送資料
11curl -d 'name=Jane&age=30' https://x.com
POST URL 編碼的表單資料
curl -d '@payload.json' https://x.com
POST 從檔案讀取的資料
curl --data-urlencode 'q=hello world' https://x.com
POST 單一 URL 編碼欄位
curl --data-binary '@file.bin' https://x.com
POST 未處理的原始位元組
curl -G --data-urlencode 'q=cats' https://x.com
將資料附加為 GET 查詢字串
curl -X POST -H 'Content-Type: application/json' -d '{"name":"Jane"}' https://x.com
POST 一個 JSON 主體
curl --json '{"name":"Jane"}' https://x.com
POST JSON 並自動設定 JSON 標頭
curl -F 'name=Jane' https://x.com
送出 multipart 表單欄位
curl -F 'file=@photo.png' https://x.com
以 multipart form-data 上傳檔案
curl -F 'file=@a.pdf;type=application/pdf' https://x.com
以明確 MIME 類型上傳檔案
curl -d '' https://x.com
以空主體 POST
驗證
9curl -u user:pass https://x.com
HTTP 基本驗證
curl -u user https://x.com
基本驗證,提示輸入密碼
curl -H 'Authorization: Bearer TOKEN' https://x.com
送出 bearer token 標頭
curl --oauth2-bearer TOKEN https://x.com
送出 OAuth 2.0 bearer token
curl --digest -u user:pass https://x.com
使用 HTTP digest 驗證
curl --ntlm -u user:pass https://x.com
使用 NTLM 驗證
curl --netrc https://x.com
從 ~/.netrc 讀取憑證
curl --netrc-file creds https://x.com
從自訂 netrc 檔讀取憑證
curl -H 'X-Api-Key: KEY' https://x.com
送出 API 金鑰標頭
下載與上傳
11curl -O https://x.com/file.zip
以遠端檔名下載
curl -o out.zip https://x.com/file.zip
下載為指定檔名
curl -OL https://x.com/file.zip
下載並跟隨重新導向
curl -C - -O https://x.com/file.zip
續傳未完成的下載
curl --limit-rate 200k -O https://x.com/f
限制傳輸速度
curl -r 0-1023 -o part https://x.com/f
僅下載指定位元組範圍
curl --retry 3 -O https://x.com/f
失敗時重試下載
curl -T file.txt ftp://x.com/
以 PUT/FTP 上傳檔案
curl -T file.txt https://x.com/up
透過 HTTP PUT 上傳檔案
curl --create-dirs -o a/b/f.txt https://x.com
為輸出建立缺少的目錄
curl -# -O https://x.com/file.zip
顯示簡單進度列
Cookie
8curl -b 'session=abc123' https://x.com
內嵌送出 cookie
curl -b cookies.txt https://x.com
從檔案送出 cookie
curl -c cookies.txt https://x.com
將收到的 cookie 寫入 jar
curl -b jar.txt -c jar.txt https://x.com
讀取並更新同一 cookie jar
curl -b 'a=1; b=2' https://x.com
一次送出多個 cookie
curl -c - https://x.com
將收到的 cookie 印到 stdout
curl --junk-session-cookies -b jar.txt https://x.com
忽略 jar 中的工作階段 cookie
curl -L -c jar.txt -b jar.txt https://x.com/login
在重新導向間維持工作階段
TLS / SSL
10curl -k https://x.com
允許不安全 (略過憑證驗證)
curl --cacert ca.pem https://x.com
以自訂 CA 套件驗證
curl --capath /etc/ssl/certs https://x.com
使用 CA 憑證目錄
curl --cert client.pem https://x.com
送出用戶端憑證
curl --cert client.pem --key client.key https://x.com
使用用戶端憑證與私鑰
curl --tlsv1.2 https://x.com
要求至少 TLS 1.2
curl --tlsv1.3 https://x.com
要求至少 TLS 1.3
curl --tls-max 1.2 https://x.com
限制最高 TLS 版本
curl --ciphers ECDHE-RSA-AES128-GCM-SHA256 https://x.com
限制允許的 TLS 加密套件
curl -vI https://x.com
檢視 TLS 交握細節
代理伺服器
9curl -x http://proxy:8080 https://x.com
透過 HTTP 代理轉送請求
curl --proxy http://proxy:8080 https://x.com
設定代理 -x 的長格式
curl -x proxy:8080 -U user:pass https://x.com
向代理進行驗證
curl --proxy-user user:pass -x proxy:8080 https://x.com
代理憑證的長格式
curl --socks5 127.0.0.1:1080 https://x.com
使用 SOCKS5 代理
curl --socks5-hostname 127.0.0.1:1080 https://x.com
SOCKS5 代理並由遠端解析 DNS
curl --socks4 127.0.0.1:1080 https://x.com
使用 SOCKS4 代理
curl --noproxy example.com https://x.com
對指定主機略過代理
curl -x '' https://x.com
停用所有已設定的代理
除錯與輸出
11curl -w '%{http_code}\n' -o /dev/null -s https://x.com
僅印出 HTTP 狀態碼
curl -w '%{time_total}\n' -o /dev/null -s https://x.com
印出總傳輸時間
curl -w '@format.txt' https://x.com
從檔案讀取 write-out 格式
curl -D headers.txt https://x.com
將回應標頭傾印到檔案
curl -D - -o body.txt https://x.com
標頭輸出 stdout,主體寫入檔案
curl --trace trace.txt https://x.com
傳輸的完整十六進位追蹤
curl --trace-ascii - https://x.com
ASCII 追蹤輸出到 stdout
curl --trace-time -v https://x.com
為詳細輸出加上時間戳
curl -v https://x.com 2>&1 | less
分頁瀏覽詳細記錄
curl -sS -o /dev/null -w '%{size_download}\n' https://x.com
印出已下載位元組數
curl --libcurl out.c https://x.com
輸出等效的 libcurl C 原始碼
逾時與重試
10curl --connect-timeout 5 https://x.com
限制連線階段秒數
curl --max-time 30 https://x.com
限制整個操作時間
curl --retry 3 https://x.com
暫時性錯誤時重試
curl --retry 3 --retry-delay 2 https://x.com
重試之間等待
curl --retry 5 --retry-max-time 60 https://x.com
限制重試總耗時
curl --retry-connrefused https://x.com
連線遭拒時亦重試
curl --retry-all-errors https://x.com
任何錯誤都重試,不限暫時性
curl --speed-limit 100 --speed-time 10 https://x.com
速度過慢持續一段時間則中止
curl --keepalive-time 60 https://x.com
設定 TCP keep-alive 間隔
curl --expect100-timeout 1 https://x.com
限制等待 100-continue 的時間
沒有條目符合「:q」。
需要協助?
使用此工具時遇到問題?請告訴我們的團隊。