Org.apache.http.client.RedirectException: Maximum redirects exceeded (50)

When you try to hit the following url:

http://www.wsj.com/video/khorasan-meet-the-new-us-terrorist-target/157FA4EF-D44F-49BA-938B-002A91A090A3.html

with HttpClient, I get the following exception =

org.apache.http.client.RedirectException: Maximum redirects (50) exceeded

Snippet of code:

    HttpClient httpclient = HttpClientBuilder.create().build();
    RequestConfig config = RequestConfig.custom().setRedirectsEnabled(true).setCircularRedirectsAllowed(true).build();

    HttpGet httpGet = new HttpGet(("http://www.wsj.com/video/khorasan-meet-the-new-us-terrorist-target/157FA4EF-D44F-49BA-938B-002A91A090A3.html"));
    httpGet.setConfig(config);
    httpGet.addHeader("Host", "online.wsj.com");
    httpGet.addHeader("User-Agent", USER_AGENT);
    httpGet.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

    httpGet.addHeader("Accept-Encoding", "gzip, deflate");
    httpGet.addHeader("Accept-Language", "en-US,en;q=0.5");
    httpGet.addHeader("Connection", "keep-alive");
    httpGet.addHeader("Content-Type", "application/x-www-form-urlencoded");

    HttpResponse httpResponse = httpclient.execute(httpGet);
    StringWriter writer = new StringWriter();
    IOUtils.copy(httpResponse.getEntity().getContent(), writer, "UTF-8");
    String theString = writer.toString();
    System.out.println(theString);

      

Any way to solve this problem? It would be very helpful!

+3


source to share





All Articles