Friday, January 29, 2016

HEAD HTTP Request

boolean isValidUrl(String url) {
 try {
  HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection()
  connection.setRequestMethod('HEAD')
  if (connection.getResponseCode() == 200) {
   return true
  }
 }
 catch(final MalformedURLException e) { }
 catch(final IOException e) { }

 return false
}

No comments:

Post a Comment