Status codes 100-101
Status codes 200-206
Status codes 300-307
Status codes 400-417
Status codes 500-505
Following is a simple program written in groovy that checks and returns the status code of any url.
import java.net.URL;
def url
def message =""
boolean fail=true
def urlString="http://192.168.0.1/test/test.html"
println checkURL(urlString)
def checkURL(urlString){
int status_code
def tempmessage=""
URL URLserver = new URL("urlString");
try{
URLConnection connection = (HttpURLConnection)URLserver.openConnection();
status_code = connection.getResponseCode();
switch (status_code)
{
case 200:
tempmessage=" Connection Successful"
break;
case 401:
tempmessage="UnAuthorised"
break;
case 405 :
tempmessage= " Resource Not Found"
break;
case 408:
tempmessage="Request Time-out"
break;
case 500:
tempmessage="Internal Server Error"
break;
case 502:
tempmessage="Bad Gateway"
break;
case 503:
tempmessage="Service Temporarily Unavailable"
break;
default :
tempmessage= connection.getResponseMessage()
break;
}
}
catch (Exception exc){
tempmessage=exc
}
return "\n "+urlString+" :"+status_code+":"+tempmessage;
}
Visit http://www.w3.org/Protocols/HTTP/HTRESP.html for detail about the status codes.