当我从应用程序运行时,我得到了下面的异常,但当我作为独立运行时,我得到了rest调用响应位置,帮助我解决了这个问题。
java.net.ProtocolException:服务器重定向次数过多(20)
public static void main(String args[]) throws Exception{
String input = new String();
Authenticator.setDefault(new MyAuthenticator());
StringBuffer url = new StringBuffer();
url.append("https://rest-call-server-URL");
URL page;
try {
page = new URL(url.toString());
URLConnection conn = (URLConnection) page.openConnection();
conn.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
input+=inputLine;
System.out.println(inputLine);
}
in.close();
// out.close();
//parseXmlList(input);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
发布于 2012-08-10 04:35:32
很有可能你已经在服务器上进入了一个重定向循环。服务器使用303 See other
进行响应,当Java连接实现自动“看到另一个”时,服务器再次使用相同的响应进行响应,以此类推。
https://stackoverflow.com/questions/11891494
复制相似问题