import uvicorn
from fastapi import FastAPI, Response
app = FastAPI()
@app.get("/legacy/")
def get_legacy_data():
data = """
Apply shampoo here.
You'll have to use soap here.
"""
# 重点就是指定 media_type
return Response(content=data, media_type="application/xml")
if __name__ == '__main__':
uvicorn.run(app="39_responses:app", reload=True, host="127.0.0.1", port=8080)
请求结果



