java.net.SocketException:连接重置jsoup

时间:2014-05-04 03:58:22

标签: java jsoup

我在以下行获取SocketException。 我有类似

的东西
    try{
        while(){
            doc = Jsoup.connect("http://ampletrails.com").timeout(300000).get();
        } 
    } catch (Exception e) {
e.printStackTrace();
}

抛出Java异常并退出程序。如何防止它在while循环中继续并阻止程序退出。

java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:185)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at sun.net.www.MeteredStream.read(MeteredStream.java:134)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)
    at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2582)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:273)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at org.jsoup.helper.DataUtil.readToByteBuffer(DataUtil.java:113)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:447)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:393)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:159)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:148)
    at base_class.main(base_class.java:20)

1 个答案:

答案 0 :(得分:0)

该异常表示服务器正在发送TCP reset以终止您正在进行的连接。

如果这是间歇性连接,则可以通过将try和catch块放在while循环内而不是外部来避免程序退出。不过,最好弄清楚服务器重置连接的原因。