lcgyh / myDocs

0 stars 0 forks source link

python request 调用接口 #45

Open lcgyh opened 6 years ago

lcgyh commented 5 years ago

post请求


import requests
import json

kw = {'adminId':'9',"companyName":"lcsunny00001","merchantGroupId":1}

headers = {
"Connection": "keep-alive",
"Content-Type":"application/json;charset=UTF-8",
"Authorization": "Bearer 5bfab9d9-3510-45c8-b7aa-9ce0b85bfc63"  # token 模拟了登录用户
}

# post请求
# json.dumps 将字典转化为json字符串
response = requests.post("https://test-robot.deepblueai.com/api/merchant/company", data = json.dumps(kw), headers = headers)
response.encode = 'utf-8' #指定编码格式
# 查看响应内容,response.text 返回的是Unicode格式的数据
print(response.content)

# 查看响应内容,response.content返回的字节流数据
# print respones.content

# 查看完整url地址
# print response.url

# 查看响应头部字符编码
# print response.encoding

# 查看响应码
# print response.status_code
lcgyh commented 5 years ago

参考 中文文档