curl
使用 curl 發送 POST 請求並讀取網站的響應:
$ curl url -d "key1=value1&key2=value2..."
-d:以POST方式提交用戶數據。 字符串參數形式類似於GET請求,每對 key=value 之間用 & 分隔。
[ming@localhost ~]$ url="http://httpbin.org/post"
[ming@localhost ~]$ curl $url -d "name=ming&contry=China"
{
"args": {},
"data": "",
"files": {},
"form": {
"contry": "China",
"name": "ming"
},
"headers": {
"Accept": "*/*",
"Content-Length": "22",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "curl/7.29.0"
},
"json": null,
"origin": "222.201.187.76, 222.201.187.76",
"url": "https://httpbin.org/post"
}
wget
使用 wget 發送 POST 請求並讀取網站的響應:
$ wget url --post-data "key1=value1&key2=value2..."
[ming@localhost ~]$ url="http://httpbin.org/post"
[ming@localhost ~]$ wget $url --post-data "name=ming&contry=China"
--2019-12-23 01:54:01-- http://httpbin.org/post
Resolving httpbin.org (httpbin.org)... 54.172.95.6, 34.193.212.251
Connecting to httpbin.org (httpbin.org)|54.172.95.6|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 411 [application/json]
Saving to: ‘post’
100%[===============================================================================================================>] 411 --.-K/s in 0s
2019-12-23 01:54:03 (24.5 MB/s) - ‘post’ saved [411/411]
[ming@localhost ~]$ cat post
{
"args": {},
"data": "",
"files": {},
"form": {
"contry": "China",
"name": "ming"
},
"headers": {
"Accept": "*/*",
"Content-Length": "22",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "Wget/1.14 (linux-gnu)"
},
"json": null,
"origin": "222.201.187.76, 222.201.187.76",
"url": "https://httpbin.org/post"
}