简体   繁体   English

SocketTimeoutException:读取超时,如何解决?

[英]SocketTimeoutException: Read timed out, how to fix it?

I have a swing application that read HTML pages using the following command 我有一个使用以下命令读取HTML页面的swing应用程序

String urlzip = null;
try {
        Document doc = Jsoup.connect(url).get();
        Elements links = doc.select("a[href]");
        for (Element link : links) {
            if (link.attr("abs:href").contains("BcfiHtm.zip")) {
                urlzip = link.attr("abs:href").toString();
            }
        }
    } catch (IOException e) {
        textAreaStatus.append("Failed to get new file from internet:"+e.getMessage()+"\n");
        e.printStackTrace();
    }
return urlzip;

then my swing application will return a string, It works fine and it reads any HTML page that I give to it. 然后我的swing应用程序将返回一个字符串,它工作正常,它读取我给它的任何HTML页面。 However, some times the application gave me the following error type Exception report. 但是,有时应用程序给了我以下错误类型异常报告。 How can i increase timeOut? 我怎样才能增加时间?

这个页面上有一个例子。

Jsoup.connect("http://example.com").timeout(3000)

This error occurs while you are trying to read data and because of large data or connection problem it can not complete the task. 当您尝试读取数据时会发生此错误,并且由于大数据或连接问题,它无法完成任务。 I would suggest you to increase your Timeout using above code atleast for 1 minute. 我建议你使用上面的代码增加你的超时至少1分钟。 so it will be like below code, 所以它会像下面的代码,

Jsoup.connect("http://example.com").timeout(60000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM