我有这个简单的代码片段试图通过NTLM身份验证连接到Windows Server。它适用于Linux,MacOS但不适用于Windows 10.在Windows上它始终抛出java.io.IOException身份验证失败。
public static void main(String[] args) throws IOException {
Authenticator myAuth = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("domain\\myusername", "password".toCharArray());
}
};
Authenticator.setDefault(myAuth);
URL url = new URL("http://url.to.server");
InputStream ins = url.openConnection().getInputStream();
System.out.println("done");
}
这是在url.openConnection()期间发生的,它会抛出此异常:
Exception in thread "main" java.io.IOException: Authentication failure
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1696)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
at de.agentes.soap.client.demo.SoapClientDemoApp.main(SoapClientDemoApp.java:24)
有没有人有过这个问题的经验?