공부
[Java] HttpURLConnection timeout settings
승가비
2019. 6. 30. 01:52
728x90
try {
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("HEAD");
con.setConnectTimeout(5000); //set timeout to 5 seconds
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
} catch (java.net.SocketTimeoutException e) {
return false;
} catch (java.io.IOException e) {
return false;
}
[출처] https://stackoverflow.com/questions/2799938/httpurlconnection-timeout-settings
728x90