我正在通过一些代理服务器执行一些请求。定义要使用的代理 URL 的函数将从代理列表中随机选择。我想知道对于给定的请求,正在使用哪个代理URL。据我所知,使用代理服务器时,http标头保持不变,但tcp标头是更改的标头。
下面是一些代码来说明它(为简单起见,没有错误处理):
func main() {
transport := &http.Transport{Proxy: chooseProxy}
client := http.Client{Transport: transport}
request, err := http.NewRequest(http.MethodGet, "https://www.google.com", nil)
checkErr(err)
// How to know here which proxy was used? Suppose the same client will perform several requests to different URL's.
response, err := client.Do(request)
checkErr(err)
dump, _ := httputil.DumpRequest(response.Request, false)
fmt.Println(dump)
}
func chooseProxy(request *http.Request) (*url.URL, error) {
proxies := []string{"proxy1", "proxy2", "proxy3"}
proxyToUse := proxies[rand.Intn(len(proxies))]
return url.Parse(proxyToUse)
}
我假设即使使用相同的客户端,也会为每个请求调用传输中的 Proxy 函数,如“Proxy 指定一个函数以返回给定请求的代理”的文档。我说的对吗?
明月笑刀无情
慕无忌1623718
烙印99
相关分类