-2

Here is my code in jsp:

<c:catch var="feederror">
    <%
        String feedUrl = (String) pageContext.getAttribute("url");
        String feedXml = "";  
      HttpURLConnection conn = (HttpURLConnection) new URL(feedUrl).openConnection();
      BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
      String line;
      while ((line = reader.readLine()) != null) {
          feedXml += line;
      }
      reader.close();
      pageContext.setAttribute("feedXml", feedXml.trim().replaceAll("",""));    
    %>
</c:catch>

The variable feederror returns java.net.ProtocolException: Server reditected too many times(20).

I have tried:

  • to open browser with disabled cookies - page do not load at all (404);
  • used CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)) before openning connection - didn't change anything;
  • tried CookieHandler.setDefault(new CookieManager()) - didn't change anything;

How to solve the problem?

Pavlo Zvarych
  • 565
  • 2
  • 8
  • 13

1 Answers1

1

java.net.ProtocolException: Server reditected too many times(20).

This exception comes from HttpURLConnection conn = (HttpURLConnection) new URL(feedUrl).openConnection();

For 99% you're calling an url, which sends a redirect to itself, or site B, which redirect to site A, which redirects to site B etc. so there is a loop.

Check what URL you're trying to call and verify it via some external tool, so you can check headers and responses from external server.

I think it has nothing to do with cookies

macvek
  • 46
  • 5