@app.get("/async")
async def async_root(user_agent: Annotated[str | None, Header()] = None):
return {"user_agent": user_agent}
class HeaderModel(BaseModel):
name: str
host: str
port: int
format: str
encoding: List[str]
@app.get("/async")
async def async_root(h: Annotated[HeaderModel, Header()]):
"""
curl -X 'GET' \
'http://127.0.0.1:18081/async' \
-H 'accept: application/json' \
-H 'name: aaa' \
-H 'host: 192.168.0.1' \
-H 'port: 1234' \
-H 'format: json' \
-H 'encoding: utf-8,base64'
"""
return {"message": h}
Cookie 和 HTTP Header 都是用于在客户端和服务器之间传递信息的机制,但它们在用途、格式和工作方式上有一些重要的区别。以下是它们之间的主要区别:
Content-Type
: 指定请求或响应的内容类型(如 application/json
)。Authorization
: 用于传递认证信息。User-Agent
: 指定发起请求的客户端软件信息。Set-Cookie
响应头来发送 Cookie。原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。