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)
答案 0 :(得分:3)
我认为你支持代理。如果您知道代理详细信息,可以尝试以下操作:
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();
答案 1 :(得分:0)
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();