Hi Ryan, That is the strange thing, I can connect with telnet to both. Also, I have been testing with a unix utility called proxychains and I am able to chain them together with that. With HttpClient, I can use either proxy as a one hop, but it doesn't work as a two hop regardless of the order of the proxies. The proxies I am testing with are just http proxies from one of the various sites online that list them.
On Fri, Jun 6, 2014 at 4:40 AM, R Smith [via HttpComponents] < [email protected]> wrote: > It looks like your tunnel proxy might not allow "CONNECT" statements. You > should test first manually, using a telnet client. If it works in telnet, > it should work in httpclient. hth. > > > On Thu, Jun 5, 2014 at 9:01 PM, galengt <[hidden email] > <http://user/SendEmail.jtp?type=node&node=23558&i=0>> wrote: > > > Hi Ryan and Oleg, > > > > Thanks for this thread, has been very helpful. Like Ryan I have 4.2 > locally > > and have overwritten createTunnelToProxy, but I think I am missing > > something. > > > > Execution looks like this: > > DefaultHttpClient client = new DefaultHttpClient(); > > HttpRoutePlanner routePlanner = new TwoHopRoutePlanner(host, port, > host2, > > port2); > > client.setRoutePlanner(routePlanner); > > client.execute(get) > > > > TwoHopRoutePlanner is super simple, implements HttpRoutePlanner and has > the > > override below: > > @Override public HttpRoute determineRoute(HttpHost target, > > HttpRequest request, HttpContext context) throws HttpException { > > HttpHost proxy1 = new HttpHost(this.host1, this.port1); > > HttpHost proxy2 = new HttpHost(this.host2, this.port2); > > HttpHost[] proxies = new HttpHost[] {proxy1, proxy2}; > > return new HttpRoute(target, null, proxies, false, > > TunnelType.TUNNELLED, LayerType.PLAIN); > > } > > } > > > > > > Here is my attempt at createTunnelToProxy: > > > > protected boolean createTunnelToProxy(HttpRoute route, int hop, > > HttpContext context) throws HttpException, IOException { > > //final HttpHost proxy = route.getProxyHost(); > > final HttpHost target = route.getTargetHost(); > > HttpResponse response = null; > > for (int i = 0; i < route.getHopCount(); i++) { > > final HttpHost proxy = route.getHopTarget(i); > > if (!this.managedConn.isOpen()) { > > this.managedConn.open(route, context, this.params); > > } > > > > final HttpRequest connect = createConnectRequest(route, > > context); > > connect.setParams(this.params); > > > > // Populate the execution context > > context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, > > target); > > context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, > proxy); > > context.setAttribute(ExecutionContext.HTTP_CONNECTION, > > managedConn); > > context.setAttribute(ExecutionContext.HTTP_REQUEST, > connect); > > > > this.requestExec.preProcess(connect, this.httpProcessor, > > context); > > > > System.out.println("CONNECT Issued: " + "host:" + > > proxy.getHostName() + " port: " + proxy.getPort() + " scheme: " + > > proxy.getSchemeName()); > > response = this.requestExec.execute(connect, > this.managedConn, > > context); > > > > response.setParams(this.params); > > this.requestExec.postProcess(response, this.httpProcessor, > > context); > > > > final int status = response.getStatusLine().getStatusCode(); > > System.out.println("CONNECT status code: " + status); > > if (status < 200) { > > throw new HttpException("Unexpected response to CONNECT > > request: " + response.getStatusLine()); > > } > > } > > final int status = response.getStatusLine().getStatusCode(); > > if (status > 299) { > > > > // Buffer response content > > final HttpEntity entity = response.getEntity(); > > if (entity != null) { > > response.setEntity(new BufferedHttpEntity(entity)); > > } > > > > this.managedConn.close(); > > throw new TunnelRefusedException("CONNECT refused by proxy: > " + > > response.getStatusLine(), response); > > } > > > > this.managedConn.markReusable(); > > return false; > > } > > > > > > I added a couple printlns in there, here is an example output: > > CONNECT Issued: host:119.2.41.98 port: 8080 scheme: http > > CONNECT status code: 200 > > CONNECT Issued: host:119.2.41.98 port: 8080 scheme: http > > CONNECT status code: 405 > > CONNECT Issued: host:www.xhaus.com port: -1 scheme: http > > CONNECT status code: 405 > > > > The body comes back with an error that includes: "The requested method > > CONNECT is not allowed for the URL /index.html". I am guessing I missed > > something in createTunnelToProxy, any help would be appreciated! > > > > > > > > -- > > View this message in context: > > > http://httpcomponents.10934.n7.nabble.com/Proxy-chaining-tp19965p23546.html > > Sent from the HttpClient-User mailing list archive at Nabble.com. > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [hidden email] > <http://user/SendEmail.jtp?type=node&node=23558&i=1> > > For additional commands, e-mail: [hidden email] > <http://user/SendEmail.jtp?type=node&node=23558&i=2> > > > > > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > http://httpcomponents.10934.n7.nabble.com/Proxy-chaining-tp19965p23558.html > To unsubscribe from Proxy chaining, click here > <http://httpcomponents.10934.n7.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=19965&code=Z2FsZW5AdGFsZW50YmluLmNvbXwxOTk2NXwxNTA1MDEwNDM=> > . > NAML > <http://httpcomponents.10934.n7.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > -- View this message in context: http://httpcomponents.10934.n7.nabble.com/Proxy-chaining-tp19965p23563.html Sent from the HttpClient-User mailing list archive at Nabble.com.
