hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: using HttpClient4.0 to retrieve files from a website.
Date Mon, 26 Oct 2009 13:00:12 GMT
nagamallika.gunturu@belgacom-ics.com wrote:
> Thanks for the response.
> 
> I have changed my code as suggested in http://hc.apache.org/httpcomponents-client/ntlm.html
and now, I just have the following message:
> 
> 
> HTTP/1.1 407 Proxy Authentication Required ( The ISA Server requires authorization to
fulfill the request. Access to the Web Proxy filter is denied.  )
> 
> Here is my complete code:
> 
> DefaultHttpClienthttpclient = 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.setAuthScope(proxyScope);
> proxyAuthState.setCredentials(new NTCredentials(proxyUser, proxypassword, localworkstation,
Domain) );localContext.setAttribute(ClientContext.PROXY_AUTH_STATE, proxyAuthState);
> 
> AuthState targetAuthState = new AuthState();
> targetAuthState.setAuthScope(targetScope);
> 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);
> httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
> 
> HttpResponse response =  null;
> HttpHost targetHost = new HttpHost(targetHost, targetPort, "https");
> try {
> response  = httpclient.execute(targetHost, httpget);
>      System.out.println("----------------------------------------");
> System.out.println(response.getStatusLine());
> }
> catch(Exception e) {
> System.out.println("Exception " + e.toString());
> 
> }
> 
> Can you please help on this?
> 


http://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.0.x/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java
http://hc.apache.org/httpcomponents-client/tutorial/html/authentication.html

Oleg

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


Mime
View raw message