Created
January 12, 2016 15:05
-
-
Save MBtech/367e3edb54de18d56219 to your computer and use it in GitHub Desktop.
Connect to a URL and check the response code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URL u = new URL ( "http://www.example.com/"); | |
HttpURLConnection huc = ( HttpURLConnection ) u.openConnection (); | |
huc.setRequestMethod ("GET"); //OR huc.setRequestMethod ("HEAD"); | |
huc.connect () ; | |
int code = huc.getResponseCode() ; | |
System.out.println(code); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment