le mie informazioni di contatto
Posta[email protected]
2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
- from fastapi import FastAPI, Response
-
- app = FastAPI()
-
-
- # ① xml
- @app.get("/legacy")
- def get_legacy_data():
- data = """<?xml version="1.0"?>
- <shampoo>
- <Header>
- Apply shampoo here.
- </Header>
- <Body>
- You'll have to use soap here.
- </Body>
- </shampoo>
- """
- return Response(content=data, media_type="application/xml")
Diamo un’occhiata al rendimento effettivo:
Il tipo restituito è in formato xml, a indicare che la restituzione ha avuto esito positivo.
- @app.get("/legacy_with_headers")
- def get_legacy_with_headers_data():
- headers = {"X-Xtoken": "LC", "Content-Language": "en-US"}
- data = """<?xml version="1.0"?>
- <shampoo>
- <Header>
- Apply shampoo here.
- </Header>
- <Body>
- You'll have to use soap here.
- HERE SOMETHING HEADER YOU DEFINED
- </Body>
- </shampoo>
- """
- return Response(content=data, media_type="application/xml", headers=headers)
Diamo un’occhiata al rendimento effettivo
L'interfaccia corrispondente può restituire normalmente e le intestazioni corrispondenti possono restituire normalmente.
- @app.get("/legacy_with_header_cookie")
- def legacy_with_header_cookie():
- headers = {"X-Xtoken": "LC-1", "Content-Language": "en-US"}
- data = """<?xml version="1.0"?>
- <shampoo>
- <Header>
- Apply shampoo here.
- </Header>
- <Body>
- You'll have to use soap here.
- HERE SOMETHING HEADER YOU DEFINED AND COOKIE
- </Body>
- </shampoo>
- """
- response = Response(content=data, media_type="application/xml", headers=headers)
- response.set_cookie(key="cookie_key_lc", value="mrli")
- return response
Diamo un’occhiata al rendimento effettivo
L'interfaccia può restituire i cookie che impostiamo normalmente e anche le intestazioni possono essere restituite normalmente.