Curl命令模拟Post/Get请求

Curl命令模拟Post请求(😗)

如,post接口请求的链接为:
https://api.xxxx.com/xxx/search/list?c={“cc”:1602,“ct”:20,“dt”:1,“ov”:20,“p”:xxx,“v”:“000”}

post入参为:
{
“catId”: 0,
“customMode”: 0,
“displayType”: 0,
“gpPlan”: “方案A”,
“height”: 0,
“isDirectSearch”: true,
“isShowDot”: false,
“keyword”: “三亚”,
}

转为curl命令后:

curl -i -k  -H "Content-type: application/json" -X POST -d '{
"catId": 0,
"customMode": 0,
"displayType": 0,
"gpPlan": "方案A",
"height": 0,
"isDirectSearch": true,
"isShowDot": false,
"keyword": "三亚",
}' https://api.xxx.com/xxx/search/list

注意:-d后面,json入参,用单引号括住;最后是http链接,若c参无用,可以省略掉,只传有意义的参数即可。

Curl命令模拟Get请求

原get请求接口:
https://api-p.xxx.com/res/pack/xxx/app?d={“bookCityCode”:1602,“bookCityName”:“南京”,“destCityCatId”:0,“destCityCode”:0,“destCityName”:“三亚”,“positionId”:1}&c={“cc”:1602,“ct”:20,“dt”:1,“ov”:20,“p”:14584,“v”:“10.21.0”}

转curl命令后:
方式1:
curl https://api.xxx.com/res/pack/getCardInfo/app?bookCityCode=1602&bookCityName=南京&destCityCatId=0&destCityCode=0&destCityName=三亚&positionId=1

curl  https://api.xxx.com/res/pack/getCardInfo/app?bookCityCode=1602\&bookCityName=南京\&destCityCatId=0\&destCityCode=0\&destCityName=三亚\&positionId=1

方式2:
此方法更为简洁,注意可以加-i -v参数查看接口详细请求内容
curl -H “Content-Type:application/json” -G -d ‘d={“bookCityCode”:1602,“bookCityName”:“南京”,“destCityCatId”:0,“destCityCode”:0,“destCityName”:“三亚”,“positionId”:1}’ https://api.xxx.com/res/pack/getCardInfo/app

curl -H "Content-Type:application/json" -G -d 'd={"bookCityCode":1602,"bookCityName":"南京","destCityCatId":0,"destCityCode":0,"destCityName":"三亚","positionId":1}' https://api.xxx.com/res/pack/getCardInfo/app

注意:c参数对接口返回无实际作用,省略掉。
d参数要手动拼接到http链接后面。注意第一参数前用"?“符号,
之后用”\&",注意前面有"\"。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章