Hi,
I am trying to access the web through our corporate proxy server with
uses NTLM. I have not been able to authenticate - receive 407 error.
Attached is the code I'm using. When viewing the proxy logs, they said
that I was not passing any credentials to the proxy server and that is
why I failed. Where did I go wrong?
import java.util.*;
import java.io.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.auth.*;
public class HttpClientNTLM {
private static String url = "http://www.google.com/";
public static void main(String[] args) {
// Create an instance of HttpClient.
HttpClient client = new HttpClient();
String NTUser=username;
String NTPwd=password;
String NTDomain=domain;
client.getHostConfiguration().setHost("www.google.com");
client.getHostConfiguration().setProxy(proxy host, 8080);
List authPrefs = new ArrayList();
authPrefs.add(AuthPolicy.NTLM);
client.getState().setProxyCredentials(
new AuthScope(null, 8080, null),
new NTCredentials(NTUser, NTPwd, "", NTDomain));
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
authPrefs);
// Create a method instance.
GetMethod method = new GetMethod(url);
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
// Read the response body.
byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not
binary data
System.out.println(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
}
}
-------------------------------------------------------------------------------
This message and any included attachments are from Siemens Medical Solutions
USA, Inc. and are intended only for the addressee(s).
The information contained herein may include trade secrets or privileged or
otherwise confidential information. Unauthorized review, forwarding, printing,
copying, distributing, or using such information is strictly prohibited and may
be unlawful. If you received this message in error, or have reason to believe
you are not authorized to receive it, please promptly delete this message and
notify the sender by e-mail with a copy to [EMAIL PROTECTED]
Thank you