通用选项
-X --request:指定HTTP方法
-H --header:添加请求头
-d --data:发送POST数据
-v --verbose:显示详细的请求和响应信息
-u --user:添加基本的认证信息
GET请求
#基本 GET 请求
curl https://api.example.com/users
#带查询参数的 GET 请求
curl https://api.example.com/users?page=1&limit=10
#显示详细请求信息(包括响应头)
curl -v https://api.example.com/users
#将响应保存到文件
curl -o response.json https://api.example.com/users
POST请求
# 提交表单数据(application/x-www-form-urlencoded)
curl -X POST -d "username=john&email=john@example.com" https://api.example.com/users
# 提交 JSON 数据(application/json)
curl -X POST -H "Content-Type: application/json" \
-d '{"username":"john", "email":"john@example.com"}' \
https://api.example.com/users
# 上传文件
curl -X POST -F "file=@/path/to/file.jpg" https://api.example.com/upload
DELETE请求
# 基本 DELETE 请求
curl -X DELETE https://api.example.com/users/123
# 带请求头的 DELETE 请求
curl -X DELETE -H "Authorization: Bearer YOUR_TOKEN" https://api.example.com/users/123
1421

被折叠的 条评论
为什么被折叠?



