TL;DR

curl 是调试 HTTP/API 的第一工具。最常用:curl -sS URLcurl -X POST -d '{}' -H 'Content-Type: application/json' URLcurl -w '%{http_code}'

基础请求

需求命令
GET 并显示响应头curl -i URL
静默模式(不显示进度)curl -sS URL
只看响应头curl -I URL
跟随重定向curl -L URL
输出到文件curl -o file.txt URL / -O(按远程文件名)

带数据请求

需求命令
POST JSONcurl -X POST -H 'Content-Type: application/json' -d '{"k":"v"}' URL
表单提交curl -d 'k=v&k2=v2' URL
上传文件curl -F 'file=@./a.txt' URL
自定义请求头curl -H 'Authorization: Bearer TOKEN' URL
Cookiecurl -b 'name=value' URL / -c cookies.txt 保存

实用参数

参数作用
-w '%{http_code}\n'只输出状态码
--max-time 10超时(秒)
--connect-timeout 5连接超时
-k / --insecure跳过 TLS 校验(仅调试)
-x http://host:port走代理
--limit-rate 1M限速
-A 'UA'自定义 User-Agent
-u user:pass基础认证

高频排查

来源

最后更新:2026-08-02