gpt4 book ai didi

go - 通过代理重新发送请求时,无法在客户端请求中设置“Request.RequestURI”错误

转载 作者:行者123 更新时间:2023-12-03 10:09:10 44 4
gpt4 key购买 nike

当我尝试重新发送请求时,通过简单的proxy(代理代码)重新发送请求

http.HandleFunc("/",func(w http.ResponseWriter, r *http.Request) {
log.Printf("proxy rq: %v", r)
client := &http.Client{}
proxyRes, err := client.Do(r) // 👈🏻 Get "http://localhost:8097/tmp": http: Request.RequestURI can't be set in client requests
if err != nil {
log.Fatalf("err proxy request: %v",err)
}
resBody := proxyRes.Body
defer resBody.Close()
if _, err := io.Copy(w, resBody); err != nil {
log.Printf("copy error:%v\n", err)
}
})
http.ListenAndServe(":8099", nil)
与设置 http_proxy ENV(我需要捕获所有http流量)
% export http_proxy=http://localhost:8099 
% curl -v http://localhost:8097/tmp
我得到像 error
Get "http://localhost:8097/tmp": http: Request.RequestURI can't be set in client requests
我错过了什么

最佳答案

您不能将客户端请求用作Do的参数。使用与r相同的参数创建一个新请求,然后对此请求执行Do

关于go - 通过代理重新发送请求时,无法在客户端请求中设置“Request.RequestURI”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65805762/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com