Try this code:

SimpleHttpConnectionManager theConnectionManager = new
SimpleHttpConnectionManager();

HttpClient   theClient       = new HttpClient( theConnectionManager );

//Set The Proxy Host Configuration
HostConfiguration theHostConfiguration = theClient.getHostConfiguration();
theHostConfiguration.setProxy( "YOUR_PROXY_SERVER_NAME",
YOUR_PROXY_SERVER_PORT_AS_int );

//Get State
HttpState theState = theClient.getState();

//Set The Credentials
theState.setProxyCredentials( null, null, new NTCredentials(
"PROXY_USERS_NAME", "PROXY_USERS_PASSWORD", "YOUR_MACHINE_NAME" ,
"YOUR_NETWORK_DOMAIN" ) );


/***NOTE*****
PROXY_USERS_NAME = is the name that YOU! need to authenticate yourself
through proxy server
PROXY_USERS_PASSWORD = is the password 

*************/


PostMethod thePostMethod = new PostMethod(  "www.theregister.co.uk" );

thePostMethod.setRequestBody( "YOUR DATA AS STRING IF ANY" );

theHttpResponseCode = theClient.executeMethod( thePostMethod );

if ( theHttpResponseCode == HttpStatus.SC_OK )
{
...
...
...
..

Let me know if this helps

--Khalid

-----Original Message-----
From: Varley, Roger [mailto:[EMAIL PROTECTED]
Sent: Friday, November 21, 2003 11:13 AM
To: [EMAIL PROTECTED]
Subject: Problems with NTLM authentication


Hi

I'm new to HttpClient and I was hoping someone could help use the NTLM
authentication correctly. I have
the neccassary permissions because I can get to the site through Internet
Explorer without any problem.
After seeing some discussion of problems with with NTLM in -rc1 I've
upgraded to -rc2 but I still cannot
connect to the host www.theregister.co.uk.

I'm getting the error message;
"WARNING: No credentials available for the 'null' authentication realm at
www-proxy2.uk.int.atosorigin.com"

My code is below. I'm probably doing somethnig stupid, but I'd be grateful
for any pointers as to 
what I'm doing wrong

Regards
Roger Varley

import java.io.IOException;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpRecoverableException;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.SimpleHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;


public class PlayNTProxyAuthentication {
    
    /** Creates a new instance of PlayNTProxyAuthentication */
    public PlayNTProxyAuthentication() {
    }
    
    public static void main(String[] args) throws IOException {
        
        PlayNTProxyAuthentication np = new PlayNTProxyAuthentication();
        np.play();
    }
    
    private void play() throws IOException {
     
        HttpClient client = new HttpClient();
        
        
         HttpState httpState = client.getState();

/*
 * Userid = my NT UserId
 * Password = my NT Network Logon Password
 * Host = Host Name of my PC as found by running ipconfig /all. 
 */
         Credentials credentials = new NTCredentials("Userid", "Password",
"Host", null);
        
 /*
  *  www.theregister.co.uk is where I'm trying to get to
  *  www-proxy2.uk.int.atosorigin.com is the name of our internal proxy
server
  */
 
httpState.setProxyCredentials("www.theregister.co.uk","www-proxy2.uk.int.ato
sorigin.com", credentials);
        
        
        HostConfiguration hc = client.getHostConfiguration();
        hc.setProxy("www-proxy2.uk.int.atosorigin.com",8080);
        

        GetMethod method = new GetMethod("http://www.theregister.co.uk";);
        
        
        int statusCode = -1;
        int attempt = 0;
        
        while (( statusCode == -1) && ( attempt <3 )) {
            try {
                attempt++;
                statusCode = client.executeMethod(method);
            }
            catch (HttpRecoverableException e) {
                e.printStackTrace();
            }
            }
            
            if ( statusCode == -1 ) {
                throw new IOException("Connection failure");
            }
        
        String responseBody = method.getResponseBodyAsString();
        int rc = method.getStatusCode();
        method.releaseConnection();
        
        System.out.println(responseBody);
        
        
        
        
    }
    
    
}

---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to