在调用某个接口时,发现其调用接口请求体的数据格式是request payload,这个有别于一般的form data数据格式的提交,因此在调用该接口时需要如下几点:
class UserModel(BaseModel):
id: str = Field(title="用户ID")
accessToken: str = Field(title="token")
@app.post("/getInfo", name="根据用户ID查询用户信息")
def saveColdInfo(req: UserModel):
url = "http://192.168.1.103/user/getInfo"
data = {
"id": req.id,
}
headers = {
"X-Access-Token": req.accessToken,
"Content-Type": "application/json;charset=UTF-8",
}
proxies = {"http": None, "https": None}
r = requests.post(
url, data=json.dumps(data), headers&