接口:

Python 使用requests发送POST请求:
import requests
import json
url = 'https://m-t.mallcoo.cn/api/tuan/Tuan/List'
# python无法处理null这样的字符串,python中的变量“空”,不是null,也不是NULL,而是None,所以报错"NameError: name 'null' is not defined"
# 将null转化为空
global null
null = ''
# python大小写敏感,首字母大写,所以将true改为True,否则报错"NameError: name 'true' is not defined"
data = {"MallId": "10057", "CategoryId": null, "PageIndex": 0, "Count": 5, "QueryCategory": True, "QueryListType": True,
"Header": {"Token": "aGzue1eBbU-jJBwLWzj0wQQum685N9dE,15064"}}
headers = {'Content-Type': 'text/plain', 'Accept': 'application/json; charset=utf-8'}
r = requests.get(url, headers=headers, data=json.dumps(data)) # post的时候,将data字典形式的参数用json包转换成json格式
print('Request URL:', r.url)
print('Request Headers:', r.request.headers)
print('Status Code:', r.status_code)
print('Response Headers:', r.headers)
print('Response:', r.text)
运行结果:

学习网址:Requests中文文档
网友评论