gpt4 book ai didi

java - Jsoup + java.io.IOException : Too many redirects occurred trying to load URL http://iv4u. 健康/

转载 作者:行者123 更新时间:2023-12-02 10:23:53 30 4
gpt4 key购买 nike

我正在尝试使用 Jsoup 库(版本 1.11.3)读取域 - iv4u.health 的 URL 正文,但出现“重定向过多”错误。下面是我正在使用的代码 -

public class Example {

public static void main(String[] args) throws InterruptedException, ExecutionException {
crawlDomain("http://iv4u.health");
}

public static void crawlDomain(String url) {
int timeout = 30;
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout * 1000)
.setConnectionRequestTimeout(timeout * 1000)
.setSocketTimeout(timeout * 1000)
.setRedirectsEnabled(false)
.build();

CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
HttpGet request = new HttpGet(url);
CloseableHttpResponse response;
try {
HttpClientContext context = HttpClientContext.create();
response = client.execute(request, context);
int status = response.getStatusLine().getStatusCode();
if (status >= HttpStatus.SC_MULTIPLE_CHOICES && status < HttpStatus.SC_BAD_REQUEST) {
System.out.println(getURLBody(url));
}
} catch (Exception e) {
e.printStackTrace();
}
}

private static String getURLBody(final String url) {
try {
String userAgent = "Mozilla";
Document doc = Jsoup.connect(url)
.userAgent(userAgent).get();
return doc.toString();
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
}

下面是错误的堆栈跟踪 -

java.io.IOException: Too many redirects occurred trying to load URL http://iv4u.health/
at org.jsoup.helper.HttpConnection$Response.<init>(HttpConnection.java:717)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:751)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:773)
at ....

请帮我解决这个问题。任何帮助将不胜感激。该代码有时可以工作(大部分是第一次)

最佳答案

尝试使用“http://iv4u.health”的 url 值。它对我有用,所以请尝试一下。

关于java - Jsoup + java.io.IOException : Too many redirects occurred trying to load URL http://iv4u. 健康/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54125473/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com