使用 FastAPI,如何在 OpenAPI (Swagger) 文档上的请求标头上将字符集添加到内容类型(媒体类型)?
@app.post("/")
def post_hello(username: str = Form(...)):
return {"Hello": username}
Run Code Online (Sandbox Code Playgroud)
OpenAPI (http:///docs) 显示“ application/x-www-form-urlencoded ”。
我尝试改变如下:
def post_hello(username: str = Form(..., media_type="application/x-www-form-urlencoded; charset=cp932")):
return {"Hello": "World!", "userName": username}
Run Code Online (Sandbox Code Playgroud)
但不能添加charset=cp932
我想根据请求将“ application/x-www-form-urlencoded; charset=cp932 ”设置为 Content-Type 。我想获得由字符集解码的用户名。