1.使用json.dumps()方法
json.dumps()方法将字典数据转化成json类型然后传给data参数,代码如下:
import requests
import json
headers = {
'Content-Type': 'application/json',
......
}
data = {
"n": "测试logo",
"s": "TEST LOGO",
"descr": "this is demo",
"data": [],
"p": 1,
"dataPage": 0,
"icon_lists": [],
"icon_page": 1
}
url = 'http://pddwyb.com/'
response = requests.post(url=url, data=json.dumps(data), headers=headers)
print(response.json())
复制代码
2.将数据传给json参数
requests.post方法里有个json参数,当我们把数据传给json参数时,Content-Type会被自动的设置成application/json,代码如下:
import requests
headers = {
'Content-Type': 'application/json',
......
}
data = {
"n": "测试logo",
"s": "TEST LOGO",
"descr": "this is demo",
"data": [],
"p": 1,
"dataPage": 0,
"icon_lists": [],
"icon_page": 1
}
url = 'http://pddwyb.com/'
response = requests.post(url=url, json=data, headers=headers)
print(response.json())
复制代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END