GET請求
- 無參數(shù)
requests.get('http://xxxxxxx/')
- 有參數(shù)
payload = {'key1':'value','key2':'value'}
requests.get('http://xxxxxxx/',params=payload)
POST請求
- 表單提交
payload = {'key1':'value','key2':'value'}
requests.post('http://xxxxxxx/',data=payload)
- x-www-form-urlencoded形式
增加headers配置 Content-Type:application/x-www-form-urlencoded
data傳入字典
payload ={'key1':'value'遥椿,'key2':'value'}
requests.post(url, data=payload,headers={'Content-Type':'application/x-www-form-urlencoded'})
- raw(文本)提交
json形式
payload ={'some':'data'}
requests.post(url, json=payload,headers={'Content-Type':'application/json'})
或
payload ={'some':'data'}
requests.post(url, data=json.dumps(payload),headers={'Content-Type':'application/json'})
無論何種方式提交 楣责,一定要記得加上請求頭