天天看點

Curl指令模拟Post/Get請求Curl指令模拟Post請求(😗)Curl指令模拟Get請求

Curl指令模拟Post/Get請求

  • Curl指令模拟Post請求(:*)
  • Curl指令模拟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連結後面。注意第一參數前用"?“符号,

之後用”\&",注意前面有"\"。