Skip to content

Instantly share code, notes, and snippets.

@MBtech
Created January 12, 2016 15:05
Show Gist options
  • Save MBtech/367e3edb54de18d56219 to your computer and use it in GitHub Desktop.
Save MBtech/367e3edb54de18d56219 to your computer and use it in GitHub Desktop.
Connect to a URL and check the response code
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