类型一:传参为raw里面的json类型
import json
import requests
data={
"message":
{
"body": [
{
"type": "TEXT"
}
]
}
}
response = requests.request('POST', url=url, json=data)
res=json.loads(response.text)
还有一种比较特殊的,body传参为raw类型,如下图
image.png
body = {
"q": "",
"mode": "global",
"logId": "0163156093",
"dt": start_time,
"skipfile": False,
"skipimage": False,
"groups": [
{
"gid": 4178102,
"type": 1,
"joinTime": "1584183659"
},
{
"gid": 3149680,
"type": 1,
"joinTime": "1584183659"
}
]
}
response = requests.request('POST', url=url, json=self.body)
res = json.loads(response.text)
类型二:传参为form-data类型
import json
import requests
data={
"word":"okr"
}
header = {
"X-User-Name": "dangjinjin",
"X-Access-Token": "test",
"X-App-Id": "test"
}
response = requests.request('POST', url=url, params=data, headers=header)
res=json.loads(response.text)
还有一种比较特殊的,body传参为 form-data类型,其中body里面的一个值为数组类型,如下图
image.png
body = {
"q": "xls",
"uid": 1138448176,
"type": 1,
"singleBody": 3,
"tn": "mac",
"groups": '[{"gid": 5030658137,"type": 1,"joinTime": "1526441775"},'
'{"gid": 55872993,"type": 1,"joinTime": "1525850950"},'
'{"gid": 2862956994,"type": 1,"joinTime": "1576038591"}]'
}
response2 = requests.request('POST', url=url_file, params=body_group)
res2 = json.loads(response2.text)
类型三:header参数比较复杂
import json
import request
header = {
'Content-Type': 'application/json',
'adapter-data': '{"code":0,"imid":1111,"accuid":1111,"acctype":"PSP",'
'"accname":"abc","status":0,"cinfo":"{\\"loginFrom\\":\\"im_hi\\",\\"loginType\\"'
':\\"\\",\\"subpro\\":\\"\\",\\"from\\":2,\\"login_type\\":\\"mobile\\"}","imname":"abc",' '"create_time":1615539734,"hisign_status":0,"corpId":1,"corpFullName":"","corpShortName":"",' '"corpUserName":"","corpUserEmail":"dangjinjin@baidu.com","corpUserId":"dangjinjin"}'
}
body = {
"type": 0,
"chatid": 1096181120
}
response = requests.request('POST', url=url, headers=header, json=body)
res = json.loads(response.text)
网友评论