req icon indicating copy to clipboard operation
req copied to clipboard

连接建立以后切换代理不生效

Open RonaldinhoL opened this issue 6 months ago • 6 comments

Image 此处的代码导致切换代理时,使用缓存的连接去处理,但是缓存的key是简单的 host:port 而不是connectMethod,这样设置了新代理以后还是使用的以前的连接

RonaldinhoL avatar Jun 05 '25 10:06 RonaldinhoL

感觉这一段应该删除直接交给下面的 pconn.alt 去处理

RonaldinhoL avatar Jun 05 '25 10:06 RonaldinhoL

怎么不看一下我提这个问题 /笑哭

RonaldinhoL avatar Jul 01 '25 15:07 RonaldinhoL

试试 https://req.cool/zh/docs/examples/easily-write-crawlers-with-req/

 c := client.Clone().SetProxyURL(proxies[resp.Request.RetryAttempt-1]) // Create a client with proxy

0xObjc avatar Jul 07 '25 16:07 0xObjc

试试 https://req.cool/zh/docs/examples/easily-write-crawlers-with-req/

c := client.Clone().SetProxyURL(proxies[resp.Request.RetryAttempt-1]) // Create a client with proxy

我当前是这么用,但感觉只能算个trick,一个client只能设置一次代理就不合理

RonaldinhoL avatar Jul 08 '25 04:07 RonaldinhoL

试试 https://req.cool/zh/docs/examples/easily-write-crawlers-with-req/

c := client.Clone().SetProxyURL(proxies[resp.Request.RetryAttempt-1]) // Create a client with proxy

这样每次都要开一个新的client,高并发场景下资源开销很大

liiidong avatar Jul 16 '25 06:07 liiidong

踩到了相同的坑,为了省下client.clone,导致使用了缓存的连接而失去了代理配置,希望这里可以更灵活一点

bughoho avatar Sep 06 '25 12:09 bughoho