Reputation: 3723
I have return a code to read a web page using jsoup-1.7.3.jar, Its working for some websites but giviing Read timed out error for some of the URls.... .
Exception in thread "main" java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:152) at java.net.SocketInputStream.read(SocketInputStream.java:122) 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:687) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323) at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468) at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:443) at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424) at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178) at org.jsoup.helper.HttpConnection.get(HttpConnection.java:167) at Main.main(Main.java:10)
Upvotes: 1
Views: 2606
Reputation: 3005
As ooxi mentioned, you can set a timeout
Jsoup.connect("").timeout(5*1000).get() //which sets timeout for 5 seconds
Edit: You can specify the timeout though the Connection
Connection connection = Jsoup.connect("");
connection.timeout(5*1000); // which sets timeout for 5 seconds
Upvotes: 3
Reputation: 3349
Before calling .get
you can set a timeout for example
Jsoup.connect(url).timeout(0).get();
Have a look at the JavaDocs of Jsoup and Connection
Upvotes: 2