Getting URL Status in Java

by guruprasad 2014-02-27 14:29:17

To Get whether the url in active status,

1.Import the necessary header files for getting httpconnection,sockettimeout
type, and so on.

2.Do the following,


u = new URL(urlString); //for setting connection to an url type.
int statuscode=-1;
HttpURLConnection huc = ( HttpURLConnection ) u.openConnection ();
huc.setRequestMethod ("GET");
huc.connect () ;
statusCode = huc.getResponseCode(); //returns the current status of the url
through its status code.

Active Status code is 200.

Useful in accessing only active sites.




965
like
0
dislike
0
mail
flag

You must LOGIN to add comments