0

I am using Apache HttpClient library to connect to url. The network in which i am doing has a secure proxy to it. when i am using the java.net package to connect to the url i just have to add the

System.setProperty("http.proxyHost", proxy);
System.setProperty("http.proxyPort", proxyPort); 

no proxy userid and password is needed to be passed but when i am trying to connect through httpclient i am getting 407 proxy authentication error.My code is:

HttpHost proxy = new HttpHost("xyz.abc.com",8080,"http");
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);

Proxy is using NTML authentication.I don't want to pass userid and password.

4

2 に答える 2

1

I have upgraded to httpclient 4.2 and this version has out of box NTML support. Just need to add following lines to the code

HttpClient httpclient = new DefaultHttpClient();
NTCredentials creds = new NTCredentials("user", "pwd", "myworkstation", "microsoft.com");
httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);

For further reading Httpclent authentication scheme u can refer http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html#d5e947

But my question is still open, why HttpClent is not picking the system proxy as simple java program does.

于 2012-12-30T11:42:14.710 に答える
0

In order for the system properties to be picked up, you could use SystemDefaultHttpClient instead of DefaultHttpClient.

As of HttpClient 4.3, this class has been deprecated in favor of HttpClientBuilder:

HttpClient hc = new HttpClientBuilder().useSystemProperties().build();
于 2014-08-06T11:46:30.723 に答える