I use the code
public static int getResponseCode(String urlString) throws MalformedURLException, IOException {
URL u = new URL(urlString);
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.setRequestMethod("GET");
huc.connect();
return huc.getResponseCode();
}
to get the Response code. When I run the code, I get an exception java.net.ConnectException: Connection timed out at java.net.PlainSocketImpl.socketConnect(Native Method)
I printed the URl which makes this error and then loaded it in browser. the link was loaded, but after some time, around 2 mins. What could be the reason why the status code is not returned? And How can I handle this case?
Thanks for your help!
Shari