服务器重定向次数过多

时间:2012-08-09 20:31:50

标签: java httpsurlconnection

从应用程序运行时我得到以下异常,但是当我独立运行时,我得到其余的呼叫响应位置帮我解决这个问题。

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();
        }
    }

1 个答案:

答案 0 :(得分:0)

您很可能已在服务器上输入了重定向循环。服务器以303 See other响应,当Java的URL连接实现自动“看到其他”时,服务器再次响应相同的响应,依此类推,无休止。