commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vnga...@tiscali.de
Subject Re: AW: HttpClient use Proxy Server with Basic Auth
Date Mon, 06 Jun 2005 13:48:56 GMT
Hello,

Thanks for the troubleshooting link, and sorry for the noise.  HttpClient
did indeed try to use ntlm authentication with the proxy; fortunately it
is possible to override defaults and tell httpclient to use basic authentication
with a proxy.  So, for posterity, if you've got a Proxy Server which allows
mutliple authentication schemes (e.g. MS ISA Server), and you need to use
basic authentication with the proxy, do something like this:

        //httpclient, by default, attempts ntlm authentication to the proxy
server
        //we want to use basic authentication for the proxy server
        //so, we have to set the HttpClientParams accordingly.  
        HttpClientParams _clientParams = new HttpClientParams();
        BasicScheme _authScheme = new BasicScheme();
        Vector _vecAuthScheme = new Vector(1);
        _vecAuthScheme.add(_authScheme.getSchemeName());
        _clientParams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,_vecAuthScheme);
        HttpClient _client = new HttpClient(_clientParams);
        //set up the proxy
        HostConfiguration _hc = new HostConfiguration();
        String _proxyHost = System.getProperty("http.proxyHost");
        _hc.setProxy(_proxyHost, Integer.parseInt(System.getProperty("http.proxyPort")));
        _hc.setHost(_url.getHost());
        //_client.getHostConfiguration().setProxy(_proxyHost, Integer.parseInt(System.getProperty("http.proxyPort")));

        _client.setHostConfiguration(_hc);
        Credentials _creds = new UsernamePasswordCredentials(System.getProperty("http.proxyUser"),
System.getProperty("http.proxyPassword")); 
        _client.getState().setProxyCredentials(null, _proxyHost, _creds);
 

It would be nice if the Proxy Server authentication were documented somewhere.
 Googling the commons-user archives brought up only 1 thread with proxy
server authentication.  

On a different note, is it possible to set up the HttpClient to not use
the proxy for a set of hosts using wildcards in dns names (e.g. what http.nonProxyHosts
does for the URLConnection)?

Thanks for the troubleshooting pointer!

- vijay

__________________________________________________________________
Das Italien-Gewinnspiel
Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
http://spielmanege.tiscali.de/italienreise/italien.php




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message