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 Gonzalo Pennino <gp...@integrabtc.com> on 2012/05/23 21:48:32 UTC

HttpClient Proxy authentication

I'm developing an application that uses HttpClient 4.2. The app runs
in a Windows 2008 server and I can't connect through the proxy (Squid,
not sure about configuration)

With this code I can connect and print the stream:

System.setProperty("http.proxyHost", "10.9.190.251");
System.setProperty("http.proxyPort", "17118");
URL url = new URL("http://<URL HERE>");
URLConnection con = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
   System.out.println(inputLine);
in.close();

With this code, using HttpClient I can't do it:

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpHost proxy = new HttpHost("10.9.190.251", 17118, "http");
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
HttpPost method = new HttpPost(new URL(url).toURI());


I also tried this way, with no luck:

ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
                httpclient.getConnectionManager().getSchemeRegistry(),
                ProxySelector.getDefault());
httpclient.setRoutePlanner(routePlanner);


I can't find out how to setup the httpclient to work like the URLConnection.

Any help will be much appreciated!!

Regards,

Gonzalo.

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


Re: HttpClient Proxy authentication

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2012-05-23 at 16:48 -0300, Gonzalo Pennino wrote:
> I'm developing an application that uses HttpClient 4.2. The app runs
> in a Windows 2008 server and I can't connect through the proxy (Squid,
> not sure about configuration)
> 
> With this code I can connect and print the stream:
> 
> System.setProperty("http.proxyHost", "10.9.190.251");
> System.setProperty("http.proxyPort", "17118");
> URL url = new URL("http://<URL HERE>");
> URLConnection con = url.openConnection();
> BufferedReader in = new BufferedReader(new InputStreamReader(
> con.getInputStream()));
> String inputLine;
> while ((inputLine = in.readLine()) != null)
>    System.out.println(inputLine);
> in.close();
> 
> With this code, using HttpClient I can't do it:
> 
> DefaultHttpClient httpclient = new DefaultHttpClient();
> HttpHost proxy = new HttpHost("10.9.190.251", 17118, "http");
> httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
> HttpPost method = new HttpPost(new URL(url).toURI());
> 
> 
> I also tried this way, with no luck:
> 
> ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
>                 httpclient.getConnectionManager().getSchemeRegistry(),
>                 ProxySelector.getDefault());
> httpclient.setRoutePlanner(routePlanner);
> 
> 
> I can't find out how to setup the httpclient to work like the URLConnection.
> 
> Any help will be much appreciated!!
> 
> Regards,
> 
> Gonzalo.
> 

Gonzalo,

I suspect the problem can be related to NTLM authentication but since
you gave no details as to how exactly the problem manifests itself I
doubt anyone will be able to help you.

Oleg

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



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