官网:https://curl.se/
手册:https://curl.se/docs/manpage.html
脚本:https://curl.se/docs/httpscripting.html
命令:
发送 JSON 格式的 POST 请求
调用接口提交数据(需指定 Content-Type: application/json):
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-d '{"username":"testuser","email":"test@example.com"}' \
https://api.example.com/register参数:
| 参数 | 功能 | 说明 | 示例 |
| 请求方法 | |||
| -X [方法] | 指定 HTTP 请求方法(GET/POST/PUT/DELETE 等),默认是 GET | curl -X POST https://api.example.com | |
| 传递数据 | |||
| -d/--data [数据] | 发送 POST 数据(表单格式或 JSON),自动将请求头设为 application/x-www-form-urlencoded | 1. 表单数据:curl -d "name=test&age=20" https://api.example.com2. JSON 数据: curl -d '{"name":"test"}' https://api.example.com | |
| --data-urlencode [数据] | 会自动对数据进行 URL 编码(如空格转为 %20、特殊字符转义等),适合发送包含特殊字符的数据。 | ||
| -H/--header [头部] | 自定义 HTTP 请求头(如指定 JSON 格式、Token 等) | curl -H "Content-Type: application/json" -H "Token: abc123" -d '{"name":"test"}' https://api.example.com | |
| 调试与信息 | |||
| -v | 显示详细请求过程(包括请求头、响应头,调试必备) | ||
| -I | 仅获取服务器响应头(不返回响应体) |
评论