跳转到主要内容
Hello

主导航

  • 首页
用户帐户菜单
  • 登录

面包屑

  1. 首页

curl

由 Administrator, 8 九月, 2025

官网: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.com
2. 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仅获取服务器响应头(不返回响应体)  

 

标签

  • curl
  • 登录或注册以发表评论

评论

RSS源
Powered by Drupal