You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Varley, Roger" <Ro...@atosorigin.com> on 2003/11/21 18:12:31 UTC
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.atosorigin.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: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org