I am trying to authenticate against a server supporting NTLM authentication in my Java application using java.net's HttpUrlConnection.
The problem is that the application fails to send the Authenticate response.
I have attached proxy to the http connection so that the traffic is routed via fiddler. In fiddler i can see Negotiate message being sent, and server Challenge is received. But after this, the application just stops saying it got a 401, without sending the type3 authenticate message.
Any ideas? Here is the code -
Authenticator.setDefault(new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username",
"password".toCharArray());
}
});
URL url = new URL("https://service_url.svc");
// Proxy for fiddler
Proxy proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("localhost", 8888));
// Create a connection
HttpURLConnection conn = (HttpURLConnection)url.openConnection(proxy);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
InputStream is = conn.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = rd.readLine()) != null)
System.out.println(line);
rd.close();
Appreciate any help. Thanks.