python使用requests模块发送post请求时, 如何正确发送json数据

准备发送请求
注意:headers中必须包含:‘Content-Type’: ‘application/json’, 且请求时

res = requests.post(url, data=request_json, headers=headers) 正确
res = requests.post(url, json=request_json, headers=headers) tornado   服务端解析失败

request_json= json.dumps({'x1':'123', 'x2':456})
headers = {'Content-Type': 'application/json', 'Host': 'resp.xxx.we'}
url = 'http://xxxxx/xxxxx'
res = requests.post(url, data=request_json, headers=headers)
print res.headers
print res.content

#md5

hashlib.md5(res.content.strip() + 'xxxx').hexdigest()

你可能感兴趣的:(后台技术)