java.net.ProtocolException:服务器重定向次数过多 (20)
我在 Web 应用程序中使用 NTLM
身份验证,类似于 这个可以从另一个域中平静地检索一些数据。它曾经工作得很好。
JDK 1.7 升级后,我开始收到 java.net.ProtocolException:服务器重定向次数过多 (20)
异常。我不知道这是否是由于 1.7 升级而发生的(这可能只是巧合)。
代码与此几乎相同:
// Install the custom authenticator
Authenticator.setDefault(new MyAuthenticator());
// Access the page
try {
// Create a URL for the desired page
URL url = new URL("http://hostname:80/index.html");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
public class MyAuthenticator extends Authenticator {
// This method is called when a password-protected URL is accessed
protected PasswordAuthentication getPasswordAuthentication() {
// Get information about the request
String promptString = getRequestingPrompt();
String hostname = getRequestingHost();
InetAddress ipaddr = getRequestingSite();
int port = getRequestingPort();
// Get the username from the user...
String username = "myusername";
// Get the password from the user...
String password = "mypassword";
// Return the information
return new PasswordAuthentication(username, password.toCharArray());
}
}
有人可以在这方面帮助我吗?
I'm using NTLM
authentication in my web application similar to this one to restfully retrieve some data from another domain. It used to work fine.
After JDK 1.7 upgrade, I've started receiving java.net.ProtocolException: Server redirected too many times (20)
exception. I don't know if it's happening due to 1.7 upgrade (it could just be a coincidence).
The code is pretty much the same as this:
// Install the custom authenticator
Authenticator.setDefault(new MyAuthenticator());
// Access the page
try {
// Create a URL for the desired page
URL url = new URL("http://hostname:80/index.html");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
public class MyAuthenticator extends Authenticator {
// This method is called when a password-protected URL is accessed
protected PasswordAuthentication getPasswordAuthentication() {
// Get information about the request
String promptString = getRequestingPrompt();
String hostname = getRequestingHost();
InetAddress ipaddr = getRequestingSite();
int port = getRequestingPort();
// Get the username from the user...
String username = "myusername";
// Get the password from the user...
String password = "mypassword";
// Return the information
return new PasswordAuthentication(username, password.toCharArray());
}
}
Could anyone please help me in this regard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论