![](/img/trans.png)
[英]java.net.ProtocolException: Server redirected too many times (20)
[英]java.net.Authenticator : java.net.ProtocolException: Server redirected too many times (20)
我們正在通過weblogic服務器(node1 / node2)上的java獨立示例代碼使用代理設置調用URL。 該代碼在節點1上工作正常,但相同的代碼在node2服務器上不工作。 我們已經檢查了代理設置和憑據都很好,但是仍然出現以下錯誤:
java.net.ProtocolException: Server redirected too many times (20)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)
at ProxyCode.start2(ProxyCode.java:54)
at ProxyCode.main(ProxyCode.java:23)
Exception in thread "Main Thread" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at ProxyCode.readFromInputStream(ProxyCode.java:65)
at ProxyCode.start2(ProxyCode.java:59)
at ProxyCode.main(ProxyCode.java:22)
另外,請在下面找到我的代碼段:SimpleAuthenticator.java
導入java.net.Authenticator; 導入java.net.PasswordAuthentication;
public class SimpleAuthenticator extends Authenticator
{
private String username;
private String password;
public SimpleAuthenticator(String username,String password)
{
this.username = username;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(
username,password.toCharArray());
}
}
主類:
String url = "http://www.oracle.com/technetwork/java/readme-2-149793.txt";
String proxy = "proxyserver";
String port = "8080";
String username = "username";
String password = "password";
Authenticator.setDefault(new SimpleAuthenticator(username,password));
URL server = null;
try {
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
server = new URL(url);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost", proxy);
systemProperties.setProperty("http.proxyPort", port);
InputStream in = null;
URLConnection connection = null;
try {
connection = (URLConnection) server.openConnection();
connection.connect();
in = connection.getInputStream();
}
catch (IOException e) {
e.printStackTrace();
}
System.out.println(readFromInputStream(in));
}
public static String readFromInputStream(InputStream in) {
StringBuffer strBuf = new StringBuffer();
char ac[];
BufferedReader buf = new BufferedReader(new InputStreamReader(in));
try
{
while (buf.ready()) {
ac = new char[10000];
buf.read(ac);
strBuf.append(ac);
}
buf.close();
}
catch (IOException e) {
e.printStackTrace();
}
自幾個月以來,我們一直處於這種狀態,無法在任何地方獲得任何有用的信息。 請幫助。謝謝
如果您提供錯誤的憑據(用戶名或密碼),則會收到此錯誤。 這是基於Glassfish的網絡應用程序發生的。 我當時期待401回應。
我認為,身份驗證器會多次嘗試相同的憑據。
找到了這個未解決的問題,看起來仍然沒有解決。 您的用戶沒有訪問權限,但沒有再次提示,而是一次又一次地與同一用戶重試
更新:問題有另一張票證打開-這顯然是預期的行為,並且
“為了克服這個問題,您的
Authenticator::getPasswordAuthentication
需要提供一種方法,如果初始身份驗證嘗試失敗,則該方法可以收集正確的密碼。”
有關更多信息,請參見票證或java.net.Authenticator
文檔 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.