Mayank Jain
Mayank Jain

Reputation: 405

jsoup SocketTimeout Exception

Jsoup is giving time out error. How can I fix this?

The line of code that gives error is

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

Exception I am getting is

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)

Upvotes: 3

Views: 1930

Answers (2)

Daniel
Daniel

Reputation: 855

I am having this same problem with jsoup 1.7.3.

Jsoup appears to have a bug, as confirmed by the following code (copied from my application but not unit tested, so maybe this bug isn't always reproducible):

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();

Upvotes: 1

1218985
1218985

Reputation: 8012

I think you are behind a proxy. You can try the following if you know your proxy details:

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();

Upvotes: 4

Related Questions