📖 curl 命令速查

按使用场景分组,点击"复制"按钮一键复制命令

基础请求
GET 请求
curl https://<host>/api/users
POST 发送 JSON
curl -X POST https://<host>/api/users -H "Content-Type: application/json" -d '{"name":"tom"}'
PUT 更新资源
curl -X PUT https://<host>/api/users/1 -H "Content-Type: application/json" -d '{"name":"jerry"}'
DELETE 删除资源
curl -X DELETE https://<host>/api/users/1
查询参数自动 URL 编码(中文 / 空格)
curl -G https://<host>/search --data-urlencode "q=中文 空格"
请求头与认证
自定义请求头(链路追踪)
curl -H "X-Trace-Id: abc123" https://<host>/api
Bearer Token 鉴权
curl -H "Authorization: Bearer <token>" https://<host>/api
Basic 认证
curl -u <user>:<password> https://<host>/api
携带 Cookie 复用会话
curl -b "session=<sid>" https://<host>/api
设置 User-Agent(绕过 UA 拦截)
curl -A "Mozilla/5.0" https://<host>
表单与文件
提交 application/x-www-form-urlencoded 表单
curl -X POST https://<host>/login -d "username=tom&password=123"
上传文件(multipart/form-data)
curl -F "file=@<path>" https://<host>/upload
下载文件并保留远端文件名
curl -O https://<host>/file.zip
断点续传下载大文件
curl -C - -O https://<host>/big.iso
调试与排错
只查看响应头(HEAD 请求)
curl -I https://<host>
显示完整请求与响应过程
curl -v https://<host>/api
忽略 HTTPS 证书校验 ⚠️(仅自签测试环境)
curl -k https://<host>/api
跟随 301 / 302 重定向
curl -L https://<host>
设置连接与总超时
curl --connect-timeout 5 --max-time 20 https://<host>/api