通过反向代理实现访问biying,目前访问一些网站需要绕过cloudfare还没有解决,代码如下:
from fastapi import FastAPI, Request
from fastapi.responses import StreamingResponse
import httpx
import uvicorn
import logging# 设置日志
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)app = FastAPI()# Claude API的目标地址
TARGET_URL = "https://www.bing.com/"# 创建一个异步HTTP客户端
async_client = httpx.AsyncClient(base_url=TARGET_URL, follow_redirects=True)@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
async def proxy(request: Request, path: str):# 构建目标URLtarget_url = f"/{path}"# 打印原始请求头logger.info("Original headers:")fo