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鏈接後面。注意第一參數前用"?“符號,
之後用”\&",注意前面有"\"。

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