You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Li Li <fa...@gmail.com> on 2014/01/14 10:10:21 UTC

how to get proxy chain work?

from https://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html
Even though HttpClient is aware of complex routing scemes and proxy
chaining, it supports only simple direct or one hop proxy connections
out of the box.

is there any working example of a two hog proxy chains?

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: how to get proxy chain work?

Posted by Sivasubramaniam Sivakumar <ss...@gmail.com>.
Hi,

HttpClient does not support proxy chaining. Related sample code below -

Sample code to create an HttpRoutePlanner that returns an HttpRoute
instance with two proxies -

        HttpRoutePlanner routePlanner = new HttpRoutePlanner() {

            public HttpRoute determineRoute(
                    HttpHost target,
                    HttpRequest request,
                    HttpContext context) throws HttpException {
                HttpHost proxy1 = new HttpHost("10.11.12.13", 2014);
                HttpHost proxy2 = new HttpHost("10.11.12.14", 2015);
                HttpHost[] proxies = new HttpHost[] {proxy1, proxy2};

                return new HttpRoute(target, null,  proxies, false,
TunnelType.PLAIN, LayerType.PLAIN);
            }
        };

You can then create a CloseableHttpClient instance using -

CloseableHttpClient httpclient = HttpClients.custom()
        .setRoutePlanner(routePlanner)
        .build();

Executing a request using this client results in this error -

Exception in thread "main" org.apache.http.client.ClientProtocolException
	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:188)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
	at com.siva.demo.HttpProxyClient.main(HttpProxyClient.java:65)
Caused by: org.apache.http.HttpException: Proxy chains are not supported.
	at org.apache.http.impl.execchain.MainClientExec.createTunnelToProxy(MainClientExec.java:526)
	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:391)
	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218)
	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194)
	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
	... 3 more

If you wish to redirect requests through two proxies, you can check if the
first proxy supports proxy chaining and configure it to redirect requests
through the second proxy.

Thanks,
Siva




On Tue, Jan 14, 2014 at 2:40 PM, Li Li <fa...@gmail.com> wrote:

> from
> https://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html
> Even though HttpClient is aware of complex routing scemes and proxy
> chaining, it supports only simple direct or one hop proxy connections
> out of the box.
>
> is there any working example of a two hog proxy chains?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>