commons-user mailing list archives

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

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
        //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);
        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")));
        //_client.getHostConfiguration().setProxy(_proxyHost, Integer.parseInt(System.getProperty("http.proxyPort")));

        Credentials _creds = new UsernamePasswordCredentials(System.getProperty("http.proxyUser"),
        _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.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message