python接口自动化--post请求
post请求
不带body的post请求
1 import requests 2 3 url = "http://japi.juhe.cn/qqevaluate/qq" 4 5 #appkey为个人申请 6 #此接口参数不在body中,参数在url?后,所以加参数params 7 par = { 8 "key":"xxxxxxxxxxx", 9 "qq":"741841851", 10 } 11 res = requests.post(url=url,params=par) 12 print(res.text) 13 print(res.json())
post请求参数
body为x-www-form-urlcoded,参数传data
1 import requests 2 3 import json 4 url = 'http://xxx' 5 6 f = { 7 "REQ_HEAD": { 8 "SIGN": "00FC2629A324F17BF64AF1F20312A631" 9 }, 10 "REQ_BODY": { 11 "txnTime": "111448", 12 "sysVersion": "5.1.1", 13 "loginType": "LPWD", 14 "regId": "", 15 "city": "北京市", 16 "province": "北京市", 17 "custMobile": "15900000205", 18 "addrDetail": "东城区锡拉胡同在北京利生体育商厦附近", 19 "sysType": "Android", 20 "custId": "", 21 "appVersion": "1.0.8", 22 "appSource": "Android", 23 "MODEL": "sm-g530h", 24 "ip": "fe80::2db:1fff:fe6a:9c5f%eth0", 25 "MANUFACTURER": "samsung", 26 "sysTerNo": "61bece283ac12058", 27 "txnDate": "190709", 28 "custPwd": "27E4E456DA788834E4DBBEB58622F73C" 29 } 30 } 31 f = json.dumps(f)#序列化成json字符串 32 # print(type(f)) 33 body = { 34 "REQ_MESSAGE":f, 35 } 36 37 h = { 38 "Content-Type":"application/x-www-form-urlencoded", 39 "User-Agent":"okhttp/3.9.1", 40 # "Accept-Encoding":"gzip", 41 # "Accept":"*/*", 42 } 43 res = requests.post(url=url,data=body,headers=h) 44 print(res.json()) 45 print(res.text)