curl命令速查
请求发送、表单上传、认证、下载重试、代理证书、调试输出等 109 条常用命令
共 109 条命令 · 10 类场景 · 点击右侧图标可复制
| 命令 | 说明 | 复制 |
|---|---|---|
curl https://example.com | 发起 GET 请求并把响应体输出到终端 | |
curl -o page.html https://example.com | 把响应保存到指定文件 | |
curl -O https://example.com/app.tar.gz | 用远程文件名保存到本地 | |
curl -s https://api.example.com/health | 静默模式,隐藏进度条与错误提示 | |
curl -sS https://api.example.com/health | 静默但仍显示错误,脚本里最常用 | |
curl -i https://example.com | 输出中包含响应头 | |
curl -I https://example.com | 只取响应头(HEAD 请求),快速探活 | |
curl -v https://example.com | 显示请求头、响应头与 TLS 握手过程 | |
curl -L https://example.com | 自动跟随 3xx 重定向 | |
curl --max-time 5 https://example.com | 整个请求最多 5 秒,超时立即失败 | |
curl -w "%{http_code}\n" -o /dev/null -s https://example.com | 只输出 HTTP 状态码 | |
curl -A "Mozilla/5.0 (Windows NT 10.0)" https://example.com | 自定义 User-Agent | |
curl -e https://google.com https://example.com | 设置 Referer 请求头(防盗链测试) | |
curl --compressed https://example.com | 请求并自动解压 gzip/br 响应 | |
curl -4 https://example.com 与 curl -6 https://example.com | 强制使用 IPv4 或 IPv6 解析与连接 |
| 命令 | 说明 | 复制 |
|---|---|---|
curl -X POST https://api.example.com/users | 指定请求方法为 POST | |
curl -X PUT -d @user.json https://api.example.com/users/1 | PUT 请求并从文件读取请求体 | |
curl -X DELETE https://api.example.com/users/1 | 发送 DELETE 请求 | |
curl -H "Content-Type: application/json" -d "{\"name\":\"tom\"}" https://api.example.com/users | 发送 JSON 请求体(注意转义引号) | |
curl --json "{\"name\":\"tom\"}" https://api.example.com/users | 7.82+ 简化写法,自动设置 JSON 头与 POST | |
curl -d "user=tom&age=18" https://api.example.com/form | 发送表单编码数据(默认 application/x-www-form-urlencoded) | |
curl --data-urlencode "q=中文 空格" https://api.example.com/search | 自动 URL 编码参数,避免特殊字符出错 | |
curl -G -d "page=1" -d "size=20" https://api.example.com/list | 把 -d 数据拼成 GET 查询参数 | |
curl -F "file=@/data/app.tar.gz" https://api.example.com/upload | multipart 表单上传文件 | |
curl -F "file=@a.png;type=image/png" -F "name=logo" https://api.example.com/upload | 上传文件并附加表单字段 | |
curl -T /data/app.tar.gz https://api.example.com/put | 以 PUT 方式上传整个文件 | |
curl --data-binary @payload.bin https://api.example.com/raw | 原样发送二进制数据不做处理 | |
curl -d @data.txt https://api.example.com/form | 从文件读取表单数据 | |
curl -X POST --data "" https://api.example.com/action | 发送空体 POST,部分接口要求 |
| 命令 | 说明 | 复制 |
|---|---|---|
curl -H "Content-Type: application/json" https://api.example.com | 添加单个自定义请求头 | |
curl -H "Accept: application/json" -H "X-Trace-Id: abc123" https://api.example.com | 添加多个请求头 | |
curl -H "Authorization: Bearer <token>" https://api.example.com/me | 使用 Bearer Token 认证 | |
curl -u admin:123456 https://api.example.com/basic | Basic 认证(会自动 Base64 编码) | |
curl -u admin https://api.example.com/basic | 只给用户名时交互式输入密码,避免密码进历史 | |
curl -b "sessionid=abc" https://example.com | 发送指定 Cookie | |
curl -b cookies.txt https://example.com | 从文件读取 Cookie | |
curl -c cookies.txt -b cookies.txt https://example.com/login | 保存响应 Set-Cookie 并复用它,实现会话保持 | |
curl --netrc-file ~/.netrc https://example.com | 从 netrc 读取账号密码,避免明文写在命令里 | |
curl -H "X-Forwarded-For: 1.2.3.4" https://api.example.com | 伪造转发头测试网关取 IP 逻辑 | |
curl -H "Host: example.com" http://10.0.0.5 | 指定 Host 直连内网机器测试虚拟主机 | |
curl -H "Connection: close" https://example.com | 关闭长连接,排查连接复用相关问题 |
| 命令 | 说明 | 复制 |
|---|---|---|
curl -O https://example.com/file.zip | 按远程文件名下载 | |
curl -o backup.zip https://example.com/file.zip | 下载并重命名为指定文件名 | |
curl -C - -O https://example.com/big.iso | 断点续传,中断后可继续下载 | |
curl --limit-rate 500k -O https://example.com/big.iso | 限速 500KB/s,避免占满带宽 | |
curl -r 0-1023 https://example.com/file.bin -o part1 | 只下载前 1KB(按字节范围下载) | |
curl -O https://example.com/a.txt -O https://example.com/b.txt | 一次下载多个文件 | |
curl --create-dirs -o logs/a/b.txt https://example.com/a.txt | 自动创建输出目录 | |
curl -O -J https://example.com/download?id=1 | 使用响应头中的 Content-Disposition 文件名 | |
curl -T file.txt ftp://user:pass@ftp.example.com/upload/ | 上传文件到 FTP 服务器 | |
curl -# -O https://example.com/big.iso | 用进度条代替默认的进度表 |
| 命令 | 说明 | 复制 |
|---|---|---|
curl -k https://10.0.0.5 | 跳过证书校验(自签名或内网环境临时使用) | |
curl --cacert ca.crt https://example.com | 指定自建 CA 证书链进行校验 | |
curl --cert client.crt --key client.key https://example.com | 双向 TLS(mTLS)客户端证书认证 | |
curl --cert client.p12:密码 --cert-type P12 https://example.com | 使用带密码的 PKCS#12 证书 | |
curl -v https://example.com 2>&1 | grep -i "SSL\|TLS" | 查看协商的 TLS 版本与加密套件 | |
curl --tlsv1.2 --tls-max 1.2 https://example.com | 强制使用 TLS 1.2,排查协议不兼容 | |
curl --http2 https://example.com | 强制使用 HTTP/2(HTTP/3 用 --http3) | |
curl --resolve example.com:443:10.0.0.5 https://example.com | 不改 hosts 直接指定域名解析到某个 IP,并保留 SNI | |
curl -w "%{ssl_verify_result}\n" -o /dev/null -s https://example.com | 输出证书校验结果(0 表示通过) | |
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates | 配合 openssl 查看证书有效期 |
| 命令 | 说明 | 复制 |
|---|---|---|
curl -x http://127.0.0.1:7890 https://example.com | 通过 HTTP 代理发起请求 | |
curl -x socks5h://127.0.0.1:1080 https://example.com | 通过 SOCKS5 代理(h 表示远端解析域名) | |
curl --noproxy "*" https://example.com | 忽略环境变量中的代理设置 | |
curl -4 https://example.com | 强制使用 IPv4,排查双栈解析问题 | |
curl -6 https://example.com | 强制使用 IPv6 | |
curl --interface eth0 https://example.com | 指定出口网卡,多网卡环境验证路由 | |
curl --connect-to example.com:443:10.0.0.5:8443 https://example.com | 不改 DNS 情况下把连接重定向到目标地址与端口 | |
curl --unix-socket /var/run/docker.sock http://localhost/version | 通过 Unix Socket 访问服务(如 Docker API) | |
curl --dns-servers 223.5.5.5 https://example.com | 指定 DNS 服务器(需编译 c-ares 支持) | |
curl --path-as-is https://example.com/a/../b | 不规范化路径,测试网关路径处理 |
| 命令 | 说明 | 复制 |
|---|---|---|
curl -o /dev/null -s -w "%{http_code} %{time_total}\n" https://example.com | 只输出状态码与总耗时,做接口拨测 | |
curl -w "code=%{http_code} dns=%{time_namelookup} connect=%{time_connect} total=%{time_total}\n" -o /dev/null -s https://example.com | 输出 DNS、建连、总耗时,定位慢在哪一段 | |
curl -D headers.txt -o body.txt https://example.com | 把响应头与响应体分别写文件 | |
curl -s https://api.example.com/list | jq . | 配合 jq 格式化 JSON 响应 | |
curl -s https://api.example.com/list | jq ".[] | .name" | 用 jq 提取需要的字段 | |
curl --trace trace.txt https://example.com | 输出完整的十六进制通信过程 | |
curl --trace-ascii trace.txt https://example.com | 以 ASCII 记录通信过程,便于阅读 | |
curl -v --stderr err.log https://example.com | 把调试信息写到文件,不污染标准输出 | |
curl -s -o /dev/null -w "%{size_download}\n" https://example.com/file | 输出下载字节数,验证文件完整性 | |
curl -H "Accept-Encoding: gzip" -s -o /dev/null -w "%{size_download}\n" https://example.com | 对比压缩前后的传输体积 |
| 命令 | 说明 | 复制 |
|---|---|---|
curl -L https://example.com | 跟随重定向(默认最多 50 次) | |
curl -L --max-redirs 3 https://example.com | 限制最多跟随 3 次,防止重定向死循环 | |
curl -L --post301 --post302 https://example.com | 3xx 后仍保持 POST 方法与数据 | |
curl --location-trusted https://example.com | 跨域重定向时保留认证头(谨慎使用) | |
curl -i -L https://example.com | 查看每一跳的状态码与响应头 | |
curl --proto "=https" https://example.com | 只允许 https 协议,防止被降级到明文 | |
curl --raw https://example.com | 关闭传输解码,观察原始响应 | |
curl -X OPTIONS -i https://api.example.com | 查看接口支持的跨域方法与头部 | |
curl -X OPTIONS -H "Origin: https://a.com" -H "Access-Control-Request-Method: POST" -i https://api.example.com | 模拟浏览器 CORS 预检请求 |
| 命令 | 说明 | 复制 |
|---|---|---|
curl --connect-timeout 3 https://example.com | 建连超时 3 秒 | |
curl --max-time 10 https://example.com | 整个请求总超时 10 秒 | |
curl --retry 3 https://example.com | 失败重试 3 次(瞬时网络错误) | |
curl --retry 5 --retry-delay 2 https://example.com | 重试 5 次,每次间隔 2 秒 | |
curl --retry 5 --retry-max-time 60 https://example.com | 限制重试总时长 60 秒 | |
curl --retry 5 --retry-all-errors https://example.com | 对所有错误重试(含 5xx 与超时) | |
curl --keepalive-time 30 https://example.com | 设置 TCP keepalive 空闲时间 | |
curl --speed-limit 1024 --speed-time 10 -O https://example.com/big.iso | 10 秒内低于 1KB/s 就中断,避免卡死 | |
curl --expect100-timeout 1 https://example.com/upload | 缩短 100-continue 等待,规避上传卡顿 | |
curl -m 5 -s -o /dev/null -w "%{http_code}\n" https://example.com | 5 秒超时的探活写法,适合监控脚本 |
| 命令 | 说明 | 复制 |
|---|---|---|
curl -s -o /dev/null -w "%{http_code}\n" https://example.com | 站点探活只看状态码,脚本中可判断 200 | |
curl -fsS --max-time 5 https://example.com/health || echo "服务异常" | -f 让 4xx/5xx 返回非零码,便于告警 | |
curl -s -X POST -H "Content-Type: application/json" -d @body.json https://api.example.com/v1/order | 接口调试标准写法:请求体放文件里 | |
curl -s -H "Authorization: Bearer $TOKEN" https://api.example.com/me | jq .data | 用环境变量传 Token,避免明文进历史 | |
curl -c cookie.txt -d "user=admin&pass=123" https://example.com/login && curl -b cookie.txt https://example.com/profile | 登录后带 Cookie 访问受保护页面 | |
curl -F "file=@/data/report.pdf" -H "Authorization: Bearer $TOKEN" https://api.example.com/upload | 带认证的文件上传 | |
curl -L -o app.tar.gz https://example.com/latest && tar -xzf app.tar.gz | 下载并解压,常见部署脚本片段 | |
curl --resolve api.example.com:443:10.0.0.5 -s -o /dev/null -w "%{http_code}\n" https://api.example.com | 灰度前验证新机器是否正常提供服务 | |
while true; do curl -s -o /dev/null -w "%{http_code} %{time_total}\n" https://example.com; sleep 1; done | 简单轮询观察接口可用性与耗时 |
常见问题排查
1. 返回 000 或空响应
多为域名解析、建连失败或 TLS 握手失败;用 -v 看卡在哪一步
2. 证书报错 SSL certificate problem
自签名可用 --cacert 指定 CA,仅测试环境可临时 -k
3. 上传大文件卡住
加 --expect100-timeout 1 或 -H "Expect:",绕过 100-continue 等待
4. POST 被跳转成 GET
3xx 默认转 GET,需 --post301/--post302 或直接请求最终地址
5. 中文参数乱码
用 --data-urlencode 自动编码,别手拼 URL
6. 代理不生效
检查 http_proxy/https_proxy 环境变量,必要时 --noproxy "*" 或显式 -x
相关工具
Linux命令速查
文件、文本、权限、进程、网络、磁盘、systemd与防火墙等 Linux 常用命令速查手册
Docker命令速查
镜像、容器、网络、数据卷、Compose、Swarm、清理与排障等 Docker 常用命令速查手册
Nginx命令速查
服务管理、配置指令、反向代理、HTTPS、限流缓存、日志排查等 Nginx 常用命令速查手册
K8S命令速查
集群上下文、Pod调试、工作负载、Service与Ingress、存储、权限、排障等 kubectl 常用命令速查手册
Windows CMD命令速查
文件目录、网络诊断、进程服务、系统信息、用户权限、注册表、批处理等 Windows CMD 常用命令速查手册
systemctl服务管理速查
服务启停、开机自启、unit文件编写、日志查看、定时器、依赖分析与排障等 systemctl 命令速查手册
关于curl命令速查
在线 curl 命令速查手册,按基础请求、请求方法与数据发送、请求头与认证、下载与断点续传、HTTPS 与证书、代理与网络、输出与调试、重定向与协议、超时与重试、实战组合等 10 类场景整理 120+ 条常用 curl 命令与参数,每条附中文说明和可直接复制的示例,支持关键词搜索、分类折叠和一键复制,打开网页即可查阅。涵盖 curl -X POST、-H 自定义请求头、-d 与 --data-urlencode、-F 表单上传、-u Basic 认证、Bearer Token、-b/-c Cookie、-O 下载、-C - 断点续传、--limit-rate 限速、-x 代理、-k 跳过证书校验、--resolve 指定解析、-w 输出状态码与耗时、--retry 重试、--http2、--unix-socket 等高频用法。适用于接口联调与拨测、站点可用性检查、文件上传下载、HTTPS 证书排查、代理与网络连通性验证,以及 Shell 脚本与 CI/CD 流水线中的 HTTP 调用。
核心能力
- 涵盖 curl -X POST、-H 自定义请求头、-d 与 --data-urlencode、-F 表单上传、-u Basic 认证、Bearer Token、-b/-c Cookie、-O 下载、-C - 断点续传、--limit-rate 限速、-x 代理、-k 跳过证书校验、--resolve 指定解析、-w 输出状态码与耗时、--retry 重试、--http2、--unix-socket 等高频用法
适用场景
适用于接口联调与拨测、站点可用性检查、文件上传下载、HTTPS 证书排查、代理与网络连通性验证,以及 Shell 脚本与 CI/CD 流水线中的 HTTP 调用。curl命令速查全程在浏览器中完成,无需安装插件,可放心用于日常办公与排障。
常见问题
- curl命令速查是免费的吗?需要注册或安装吗?
- curl命令速查完全免费,无需注册、无需下载安装任何软件,用浏览器打开网页即可直接使用,也不限制使用次数。
- curl命令速查支持哪些功能?
- 涵盖 curl -X POST、-H 自定义请求头、-d 与 --data-urlencode、-F 表单上传、-u Basic 认证、Bearer Token、-b/-c Cookie、-O 下载、-C - 断点续传、--limit-rate 限速、-x 代理、-k 跳过证书校验、--resolve 指定解析、-w 输出状态码与耗时、--retry 重试、--http2、--unix-socket 等高频用法。
- curl命令速查适合哪些场景使用?
- 适用于接口联调与拨测、站点可用性检查、文件上传下载、HTTPS 证书排查、代理与网络连通性验证,以及 Shell 脚本与 CI/CD 流水线中的 HTTP 调用。