方法如下:
import requests
import json
data = {
'a': 123,
'b': 456
}
## headers中添加上content-type這個參數,指定為json格式
headers = {'Content-Type': 'application/json'}
## post的時候,將data字典形式的參數用json包轉換成json格式。
response = requests.post(url='url', headers=headers, data=json.dumps(data))