python-requests 发布 JSON
例子
要发布JSON正文,请将Python数据结构传递给json参数;这里发布了一个字典,但任何可以编码为JSON的内容都可以:
import requests #创建要发送的字典。 json_data = {'foo': ['bar', 'baz'], 'spam': True, 'eggs': 5.5} #发送数据。 response = requests.post(url='http://example.com/api/foobar', json=json_data) print("Server responded with %s" % response.status_code)
requests负责编码到JSON你的,并设置Content-Type到application/json。