欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

用curl和wget发送POST请求的方法

最编程 2024-08-10 21:40:00
...
## curl发送Post请求
curl -H "User-Agents: Chrome" -H "Content-Type: Application/json" -d '{"name":"marshmallow"}' -XPOST http://httpbin.org/post 
{
  "args": {}, 
  "data": "{\"name\":\"marshmallow\"}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "22", 
    "Content-Type": "Application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.58.0", 
    "User-Agents": "Chrome", 
    "X-Amzn-Trace-Id": "Root=1-611f5974-1b572fde0be948456fc13527"
  }, 
  "json": {
    "name": "marshmallow"
  }, 
  "origin": "112.200.7.13", 
  "url": "http://httpbin.org/post"
}

-H 设置请求头
-d 设置Body
-X 指定请求方法

wget发送POST请求

wget --header="User-Agents: Chrome" --header="Content-Type: Application/json" --post-data='{"name":"marshmallow"}' http://httpbin.org/post -q -O - 
{
  "args": {}, 
  "data": "{\"name\":\"marshmallow\"}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "identity", 
    "Content-Length": "22", 
    "Content-Type": "Application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "Wget/1.19.4 (linux-gnu)", 
    "User-Agents": "Chrome", 
    "X-Amzn-Trace-Id": "Root=1-611f5980-25b6866b7ddd43ad6033a0f8"
  }, 
  "json": {
    "name": "marshmallow"
  }, 
  "origin": "112.200.7.13", 
  "url": "http://httpbin.org/post"
}

--header 设置请求头
--post-data 设置请求body
-q 静默模式
-O - 将response输出到终端

推荐阅读