You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Mike Ma <ja...@hotmail.com> on 2003/08/25 06:21:28 UTC

Help -- Proxy


First, thank you all for this wonderful httpclient library. I found it this 
weekend, and started to test the functionalities that I want. It works very 
nicely except I could not figure out how to configurate a proxy server. I 
really need to access internet using this httpclient through my company's 
proxy server.

I know the following codes work in Proxy configuration when I use JDK's 
URLConnection:

------------
    System.getProperties().put("proxySet", "true");
    System.getProperties().put("proxyHost", "www-ad-proxy.mycompany.com");
     System.getProperties().put("proxyPort", "80");
    URL url=new URL("some-url");
    URLConnection conn=url.openConnection();
    String authString="myusername:mypassword";
    BASE64Encoder encoder=new BASE64Encoder();
    String auth="Basic "+encoder.encode(authString.getBytes());
    conn.setRequestProperty("Proxy-Authorization", auth);
------------

I tried to do a get method using this httpclient module as following
---------

        HttpClient client=new HttpClient();
        HostConfiguration hostConfig=new HostConfiguration();
        hostConfig.setProxy("www-ad-proxy.mycompany.com",80);
        HttpState state=new HttpState();
        UsernamePasswordCredentials userpass=
               new UsernamePasswordCredentials("myname","mypass");
        state.setProxyCredentials(null, null, userpass);
        client.setHostConfiguration(hostConfig);
        client.setState(state);
        GetMethod method=new GetMethod("http://www.apache.org");
       ....
-----

It did not work. The warning message was:
[WARN] HttpMethodBase - -Credentials cannot be used for NTLM authentication: 
myname:mypass


Please help me

Thanks
Mike

_________________________________________________________________
MSN 8: Get 6 months for $9.95/month. http://join.msn.com/?page=dept/dialup


Re: Help -- Proxy

Posted by Ortwin Glück <or...@nose.ch>.
Mike Ma wrote:
>        UsernamePasswordCredentials userpass=
>               new UsernamePasswordCredentials("myname","mypass");
>        state.setProxyCredentials(null, null, userpass);
> [WARN] HttpMethodBase - -Credentials cannot be used for NTLM 
> authentication: myname:mypass


It seems that your proxy uses NTLM authentication. Thus you must provide 
NTLMCredentials instead of UsernamePasswordCredentials.


Re: Help -- Proxy

Posted by Michael Becke <be...@u.washington.edu>.
Hi Mike,

You've pretty much got it.  If you are authenticating to a NTLM proxy, 
you have to use NTCredentials instead of UsernamePasswordCredentials.  
Also, just to note, you don't have to create instances of 
HostConfiguration or HttpState.  You can use the ones returned from 
HttpClient.

Mike

On Monday, August 25, 2003, at 12:21 AM, Mike Ma wrote:

>
>
> First, thank you all for this wonderful httpclient library. I found it 
> this weekend, and started to test the functionalities that I want. It 
> works very nicely except I could not figure out how to configurate a 
> proxy server. I really need to access internet using this httpclient 
> through my company's proxy server.
>
> I know the following codes work in Proxy configuration when I use 
> JDK's URLConnection:
>
> ------------
>    System.getProperties().put("proxySet", "true");
>    System.getProperties().put("proxyHost", 
> "www-ad-proxy.mycompany.com");
>     System.getProperties().put("proxyPort", "80");
>    URL url=new URL("some-url");
>    URLConnection conn=url.openConnection();
>    String authString="myusername:mypassword";
>    BASE64Encoder encoder=new BASE64Encoder();
>    String auth="Basic "+encoder.encode(authString.getBytes());
>    conn.setRequestProperty("Proxy-Authorization", auth);
> ------------
>
> I tried to do a get method using this httpclient module as following
> ---------
>
>        HttpClient client=new HttpClient();
>        HostConfiguration hostConfig=new HostConfiguration();
>        hostConfig.setProxy("www-ad-proxy.mycompany.com",80);
>        HttpState state=new HttpState();
>        UsernamePasswordCredentials userpass=
>               new UsernamePasswordCredentials("myname","mypass");
>        state.setProxyCredentials(null, null, userpass);
>        client.setHostConfiguration(hostConfig);
>        client.setState(state);
>        GetMethod method=new GetMethod("http://www.apache.org");
>       ....
> -----
>
> It did not work. The warning message was:
> [WARN] HttpMethodBase - -Credentials cannot be used for NTLM 
> authentication: myname:mypass
>
>
> Please help me
>
> Thanks
> Mike
>
> _________________________________________________________________
> MSN 8: Get 6 months for $9.95/month. 
> http://join.msn.com/?page=dept/dialup
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>