1

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)

2
  • 1
    ... and what happens if you try going to one of these urls with your browser (or curl)? Commented Feb 10, 2014 at 9:37
  • @millhouse::using curl or browser they never gave me error. Commented Feb 11, 2014 at 6:47

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

3 Comments

Again it gave me same error immediately after just clicking on run even after adding timeout(5*1000)
@AnkitKumar may be code sample can help in resolving the error
in my case, I added .userAgent("Opera") option and solved the issue
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.