Java 服务器重定向次数太多

Java 服务器重定向次数太多,java,httpsurlconnection,Java,Httpsurlconnection,当从应用程序运行时,我会遇到以下异常,但当我作为独立运行时,我会得到rest调用响应位置来帮助我解决此问题 java.net.ProtocolException:服务器重定向次数太多(20次) 您很可能已经在服务器上进入了重定向循环。服务器用303 See other进行响应,当Java的URL连接实现自动“看到另一个”时,服务器再次用相同的响应进行响应,以此类推 public static void main(String args[]) throws Exception{ S

当从应用程序运行时,我会遇到以下异常,但当我作为独立运行时,我会得到rest调用响应位置来帮助我解决此问题

java.net.ProtocolException:服务器重定向次数太多(20次)


您很可能已经在服务器上进入了重定向循环。服务器用
303 See other
进行响应,当Java的URL连接实现自动“看到另一个”时,服务器再次用相同的响应进行响应,以此类推

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