Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 异常org.apache.http.client.RedirectException:超出最大重定向(50)_Java_Apache Httpclient 4.x - Fatal编程技术网

Java 异常org.apache.http.client.RedirectException:超出最大重定向(50)

Java 异常org.apache.http.client.RedirectException:超出最大重定向(50),java,apache-httpclient-4.x,Java,Apache Httpclient 4.x,当我尝试点击以下URL时: http://www.wsj.com/video/khorasan-meet-the-new-us-terrorist-target/157FA4EF-D44F-49BA-938B-002A91A090A3.html 对于HttpClient,我收到以下异常= org.apache.http.client.RedirectException:超过最大重定向(50) 代码段: HttpClient httpclient = HttpClientBuilder.c

当我尝试点击以下URL时:

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

对于HttpClient,我收到以下异常=

org.apache.http.client.RedirectException:超过最大重定向(50)

代码段:

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

有办法解决吗?那会很有帮助的

http.protocol.max重定向可以设置。见: