【发布时间】:2014-12-28 09:32:53
【问题描述】:
python Requests包中的data和json参数有什么区别?
不清楚来自the documentation
这个代码:
import requests
import json
d = {'a': 1}
response = requests.post(url, data=json.dumps(d))
请注意,我们在这里将dict 转换为 JSON ☝️!
做任何不同的事情:
import requests
import json
d = {'a': 1}
response = requests.post(url, json=d)
如果是这样,那是什么?后者是否自动将标头中的content-type 设置为application/json?
【问题讨论】:
标签: python json python-requests