curl / wget 速查表 - 命令行文件下载与 HTTP 请求大全
下载文件、调接口、排查 HTTP 问题,curl 和 wget 是命令行首选。这里按请求、下载、认证、调试分组,并给出两者对照,配示例直接复制。
返回 Web 服务基础请求 Requests 6
curl https://api.testcurl 输出响应体到 stdout
curl -O https://x/file.zipcurl 按原文件名保存(-O 大写)
curl -o out.html https://xcurl 保存到指定文件名
wget https://x/file.zipwget 默认按原文件名下载
wget -O out.html https://xwget 保存到指定文件名
curl -I https://xcurl 只取响应头(HEAD)
请求方法 Method 5
curl -X POST https://xcurl 指定请求方法
curl -d 'a=1&b=2' https://xcurl POST 表单数据(默认 application/x-www-form-urlencoded)
curl -d @body.json https://xcurl 从文件读取请求体
curl -H 'Content-Type: application/json' -d '{"a":1}' https://xcurl POST JSON
curl -T file.zip https://x/uploadcurl 上传文件(PUT)
请求头与 Cookie 5
curl -H 'Authorization: Bearer TOKEN' https://xcurl 自定义请求头
curl -b cookie.txt https://xcurl 发送 Cookie(文件)
curl -c cookie.txt https://xcurl 把响应 Set-Cookie 存到文件
wget --header="Auth: TOKEN" https://xwget 自定义请求头
wget --save-cookies c.txt --keep-session-cookies https://xwget 保存会话 Cookie
下载与续传 Download 5
curl -C - -O https://x/big.isocurl 断点续传
wget -c https://x/big.isowget 断点续传(-c)
wget -r -np -l 2 https://x/dir/wget 递归下载(限制层级)
curl -L https://xcurl 跟随重定向(-L)
wget --mirror -p --convert-links https://xwget 镜像整站并本地化链接
认证与代理 Auth & Proxy 4
curl -u user:pass https://xcurl 基础认证
curl -x http://proxy:8080 https://xcurl 走 HTTP 代理
wget -e use_proxy=yes -e http_proxy=http://proxy:8080 https://xwget 走代理
curl -k https://xcurl 跳过 TLS 证书校验(不安全)
调试与排错 Debug 5
curl -v https://xcurl 详细过程(含请求/响应头)
curl -s -o /dev/null -w "%{http_code}" https://xcurl 只取 HTTP 状态码
curl -w "@curl-format.txt" https://xcurl 用格式文件输出计时/指标
wget -S https://xwget 打印响应头
wget --debug https://xwget 调试模式
curl vs wget 对照 4
上传文件curl 强(支持 PUT/POST 任意体);wget 较弱
递归镜像整站wget 强(--mirror);curl 需手动脚本
默认输出curl 打到 stdout;wget 直接落盘
易用性wget 下载开箱即用;curl 调试/接口更灵活
💡 提示
- 下载大文件优先用续传:curl -C - -O 或 wget -c,网络断了不重来。
- curl 默认不跟随重定向,要加 -L;wget 默认跟随。
- 只取状态码排查服务:curl -s -o /dev/null -w "%{http_code}"。
- POST JSON 时必须带 -H "Content-Type: application/json",否则服务端按表单解析。
由 LaoHand 维护
公开更新于 2026年8月2日,内容持续校对官方文档。