@route.post('/')
async def return_header(name: str = Header(...),
age: str = Header(...),country: str = Header(...),
json_body : dict = Body(...)):
return get_data(json_headers, json_body)
我需要在return_header函数中添加什么,以便将所有标头存储在json_headers中
def get_data(headers=None, body=None):
url = ''
certs = ''
response = requests.post(url, cert=certs, headers=headers, json=body,
verify=False)
return some_fun(response.json())
这里有一个工作脚本
import requests
from fastapi import FastAPI, Header, Body
app = FastAPI()
def get_data(headers=None, body=None):
print(headers)
print(body)
url = ""
certs = ""
response = requests.post(url, cert=certs, headers=headers, json=body, verify=False)
return some_fun(response.json())
@app.post("/")
async def return_header(
name: str = Header(...),
age: str = Header(...),
country: str = Header(...),
json_body: dict = Body(...),
):
json_headers = {
"name": name,
"age": age,
"country": country,
}
print(json_headers, "n", json_body)
return get_data(json_headers, json_body)
输出:
{'name': 'test', 'age': 'test', 'country': 'test'}
{}