hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <nagamallika.gunt...@belgacom-ics.com>
Subject RE: using HttpClient4.0 to retrieve files from a website.
Date Mon, 26 Oct 2009 11:16:29 GMT

After some more search and reading, here is the sample code that I am trying out:

HttpClient httpclient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpget = new HttpGet("targetURL");

AuthScope proxyScope = new AuthScope(proxyHost, proxyPort);
AuthScope targetScope = new AuthScope(targetHost, targetPort);

AuthState proxyAuthState = new AuthState();
proxyAuthState.setCredentials(new UsernamePasswordCredentials(proxyUser, proxyPassword) );
localContext.setAttribute(ClientContext.PROXY_AUTH_STATE, proxyAuthState);

AuthState targetAuthState = new AuthState();
targetAuthState.setCredentials(new UsernamePasswordCredentials(webSiteUser, webSitePassword)
localContext.setAttribute(ClientContext.TARGET_AUTH_STATE, targetAuthState);

HttpHost proxy = new HttpHost(proxyHost, proxyPort);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

HttpResponse response =  null;
HttpHost targetHost = new HttpHost(targetHost, targetPort, "https");
try {
response  = httpclient.execute(targetHost, httpget);
catch(Exception e) {
System.out.println("Exception " + e.toString());


And I get the following output:
Oct 26, 2009 12:02:01 PM org.apache.http.impl.client.AbstractAuthenticationHandler selectScheme
WARNING: Authentication scheme ntlm not supported
Oct 26, 2009 12:02:01 PM org.apache.http.impl.client.DefaultRequestDirector createTunnelToTarget
WARNING: Authentication error: Unable to respond to any of these challenges: {kerberos=Proxy-Authenticate:
Kerberos, ntlm=Proxy-Authenticate: NTLM, negotiate=Proxy-Authenticate: Negotiate}
HTTP/1.1 407 Proxy Authentication Required ( The ISA Server requires authorization to fulfill
the request. Access to the Web Proxy filter is denied.  )

Can anyone please tell me whats wrong in this?


Sent: 26 October 2009 09:38
To: 'httpclient-users@hc.apache.org'
Subject: using HttpClient4.0 to retrieve files from a website.


We are trying to use HttpClient 4.0 API to connect to an internet website that requires user
authentication to retrieve files. And we connect to the internet through a proxy that also
needs a different user credentials.

All the samples that I have seen so far, do either proxy authentication or web-site authentication
but not both:

a)    Is the scenario I explained above, achievable using HttpClient? I guess it should be
possible, but I am not sure how? Can someone help me with this

And for info, the production environment will be on Linux and the development environment
is Windows..

Thanks and Regards
Mallika Gunturu


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message