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
一次调用请求多个 URL
curl 'https://x.com/p?[1-5]'
用数字范围循环 URL
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
-I 的长格式,用于 HEAD 请求
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 表单数据上传文件
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 令牌头
curl --oauth2-bearer TOKEN https://x.com
发送 OAuth 2.0 bearer 令牌
curl --digest -u user:pass https://x.com
使用 HTTP 摘要认证
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
带远程 DNS 解析的 SOCKS5 代理
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”。
需要帮助?
使用此工具时遇到问题?请告诉我们的团队。