Java 异常org.apache.http.client.RedirectException:超出最大重定向(50)
当我尝试点击以下URL时: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
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重定向可以设置。见: