3

Jsoup 给出超时错误。我怎样才能解决这个问题?

给出错误的代码行是

Document doc;
doc = Jsoup.connect("http://google.com").timeout(300000).get();

我得到的例外是

java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    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.http.HttpClient.parseHTTPHeader(HttpClient.java:633)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:579)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1322)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:412)
    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)
4

2 回答 2

4

我认为您在代理背后。如果您知道您的代理详细信息,您可以尝试以下操作:

System.setProperty("http.proxyHost", "147.167.10.2");//replace with your proxy host
System.setProperty("http.proxyPort", "8080");//replace with your proxy port
Document doc = Jsoup.connect("http://google.com").get();
于 2013-02-18T18:03:20.293 回答
1

我对jsoup 1.7.3也有同样的问题。

Jsoup 似乎有一个错误,正如以下代码所证实的那样(从我的应用程序复制但没有经过单元测试,所以也许这个错误并不总是可重现的):

Document doc;
URLConnection con = new URL("http://google.com").openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String html;
while ((html = reader.readLine()) != null) {
    System.out.println(url + ": "+ html);
}
doc = Jsoup.connect("http://google.com").timeout(300000).get();
于 2014-07-01T19:37:35.637 回答