Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.net.ProtocolException: Server redirected too many times

843841Feb 20 2006 — edited Feb 28 2006
I have a servlet where I need data from external url.
When am trying to simply request (GET) a website through a url I got the following exception:
java.net.ProtocolException: Server redirected too many times (20)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:583)

But, isn't there a redirect.

Try the code:

... change the url
 
  URL url = new URL("http://10.254.69.28:8989/ctx1/crossctx.act");
  HttpURLConnection  con = (HttpURLConnection) url.openConnection();
  con.setFollowRedirects(true);
  con.setInstanceFollowRedirects(true);
  con.connect();
 
    InputStream in = con.getInputStream();
      StringBuffer respo = new StringBuffer();
      int chr;
      int ii=0;
      while ((chr=in.read())!=-1) {
        respo.append((char) chr); ii++;
        if (ii>100) break;
      }
      in.close();
      System.out.println( respo.toString());
 
How to resolve the problem?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 28 2006
Added on Feb 20 2006
4 comments
7,600 views