Closed siwee closed 3 years ago
我打算在beforeRequest()中设置代理策略,根据不同的url使用不同的代理服务器,但是调试发现beforeRequest()并未调用,代码如下:
public class InterceptorJsIntercept2 extends FullRequestIntercept { @Override public void beforeRequest(Channel clientChannel, HttpContent httpContent, HttpProxyInterceptPipeline pipeline) throws Exception { String host = pipeline.getRequestProto().getHost(); if (host.contains("taobao.com")) { pipeline.setProxyConfig(new ProxyConfig(ProxyType.HTTP, "127.0.0.1", 8888)); } else { pipeline.setProxyConfig(new ProxyConfig(ProxyType.HTTP, "127.0.0.1", 7890)); } super.beforeRequest(clientChannel, httpContent, pipeline); } @Override public boolean match(HttpRequest httpRequest, HttpProxyInterceptPipeline pipeline) { return true; } }
aomsweet 谢谢。
FullRequestIntercept需要重写这个方法才行:
FullRequestIntercept
public void handleRequest(FullHttpRequest httpRequest, HttpProxyInterceptPipeline pipeline)
@monkeyWie 嗯嗯,后面试了这个方法,确实可以。
谢谢。
我打算在beforeRequest()中设置代理策略,根据不同的url使用不同的代理服务器,但是调试发现beforeRequest()并未调用,代码如下:
aomsweet 谢谢。