简体   繁体   中英

Server redirected too many times

I get the below exception when running from application but when i run as stand alone i get the rest call response place help me solve this problem.

java.net.ProtocolException: Server redirected too many times (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();
        }
    }

In all probability you have entered a redirect loop at the server. The server responds with 303 See other and when Java's URL connection implementation automatically "sees that other", the server responds again with the same response, and so on ad infinitum.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM