自学内容网 自学内容网

http反向代理

通过反向代理实现访问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):
    # 构建目标URL
    target_url = f"/{path}"

    # 打印原始请求头
    logger.info("Original headers:")
    fo

原文地址:https://blog.csdn.net/weixin_44772948/article/details/144655714

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!