python requests方法post请求json格式处理

方法如下:

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))

猜你喜欢

转载自www.cnblogs.com/lisa2016/p/11764074.html