Reputation: 23
Using jsoup getting java.net.SocketTimeoutException: Read timed out exception
private static void getNiftyFutureOIReader() {
String url = "https://www1.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuoteFO.jsp?underlying=NIFTY&instrument=FUTIDX&type=-&strike=-&expiry=30JAN2020";
Document doc = null;
try {
doc = Jsoup.connect(url).timeout(15*1000).get();
Element content = doc.getElementById("responseDiv");
String jsonCont=content.html();
System.out.println(jsonCont);
} catch (IOException e) {
e.printStackTrace();
}
}
i am using Jsoup to call website url and read its content, Using jsoup getting java.net.SocketTimeoutException: Read timed out exception
error log
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:750)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:722)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:306)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:295)
at code.test.BankNiftyFutureOIReader.getNiftyFutureOIReader(BankNiftyFutureOIReader.java:19)
at code.test.BankNiftyFutureOIReader.main(BankNiftyFutureOIReader.java:53)
Upvotes: 1
Views: 2115
Reputation: 3264
Based on this answer, JSoup UserAgent, how to set it right?, maybe try if the website is checking UserAgent or other Headers to verify your're not a bot. I'd expect a "live quotes" webpage to have such counter-measures.
Response response= Jsoup.connect("https://www1.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuoteFO.jsp?underlying=NIFTY&instrument=FUTIDX&type=-&strike=-&expiry=30JAN2020")
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.referrer("https://www.nseindia.com")
.timeout(15_000)
.followRedirects(true)
.execute();
// TODO: verify Response status code here!
Document doc = response.parse();
Upvotes: 3
Reputation: 2246
Problem might be due to
Make sure you are connected to the internet. Try to open same URL in the browser and see if it opens the page. or from Your VM able to reach that url simple curl / wget methods
Specify more Jsoup connection time out before getting the document as given below.
Upvotes: 0