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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to