0

我正在尝试使用 python Fast API 框架代理外部网站(在不同容器上运行的花监控 URL):

client = AsyncClient(base_url=f'http://containername:7800/monitor')

@app.get(“/monitor/{path:path}”)
async def tile_request(path: str):
    req = client.build_request("GET", path)
    r = await client.send(req, stream=True)
    return StreamingResponse(
        r.aiter_raw(),
        background=BackgroundTask(r.aclose),
        headers=r.headers
   )

它能够为每个路径代理容器 URL。例如。

http://python_server:8001/monitor/dashboard --> http://containername:7800/monitor/dashboard

http://python_server:8001/monitor/tasks --> http://containername:7800/monitor/tasks

它运作良好。但是当 PATH 在 URL 中有一些查询参数时它会失败。

例如。

http://python_server:8001/monitor/dashboard?json=1&_=1641485992460 --> redirects to http://containername:7800/monitor/dashboard 

(请注意,没有查询参数附加到 URL)。

任何人都可以帮助我们如何使用任何查询参数代理这个外部网站的任何路径。

4

0 回答 0