Groovy web console

subscribe to the feed Subscribe
to this
site

URL availability

Published 3 months ago by abdul
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
String url = "https://stackoverflow.com/questions/3584210/preferred-java-way-to-ping-an-http-url-for-availability/3584332#3584332"
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); 
connection.setRequestMethod("HEAD"); 
int responseCode = connection.getResponseCode();

println responseCode