从浏览器运行我的JavaFX应用程序时(或作为web-start),我遇到了一些奇怪的JSoup问题.
当我从IDE(Eclipse或Netbeans)内部运行或作为独立应用程序运行时,它会正常运行.当我尝试以网络启动或浏览器(Chrome)运行时,JSoup会随机抛出"java.io.IOException:stream is closed".
我试图解析的网站是thepiratebay.sx.当我第一次运行应用程序(从浏览器)时,我收到此错误.在应用程序运行的情况下,如果我再次尝试解析,那么它有效.
JSoup代码:
try {
//TODO: Change to HttpFetcher. This method is reporting "stream is closed" when running on browser
Connection con = Jsoup.connect(url)
.timeout(HTTP_TIMEOUT)
.userAgent(UserAgentGenerator.getUserAgent())
.followRedirects(false);
doc = con.get();
System.out.println("Fetching... " + url);
} catch (IOException e) {
e.printStackTrace();
System.out.println("Parser connect must have timed out, no results. " + url);
fetchFailed[i] = true;
continue;
}
finally {
i++;
if (CommonTFUtils.isAllTrue(fetchFailed)) {
throw new HttpException("Fetcher failed on every URL of " + response.getSite_name());
}
}
Run Code Online (Sandbox Code Playgroud)
抛出异常:
CacheEntry[http://thepiratebay.sx/browse/207/0/7]: …Run Code Online (Sandbox Code Playgroud)