Python 之 Requests 参数格式

x-www-form-urlencoded

requestscontent-typ"content-type": "application/x-www-form-urlencoded; charset=UTF-8", 时请求参数当如下

1
2
3
4
5
r = requests.post(
url,
headers=headers,
data=data
)

json

requestscontent-typ"Content-Type": "application/json;charset=UTF-8", 时请求参数当如下

1
2
3
4
5
r = requests.post(
url,
headers=headers,
data=json.dumps(data)
)

x-www-form-urlencoded 时应该为一个字典,json 时应该为一个 json 字符串