Advertisement
mrk1989

URLUtils

May 17th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. package com.rexuiz.checksite;
  2.  
  3. import java.net.HttpURLConnection;
  4. import java.net.URL;
  5.  
  6. public class URLUtils {
  7.  
  8. public static void main(String[] args) {
  9. System.out.println(URLUtils.checkIfURLExists("http://108.61.164.188/RexuizLauncher/"));
  10. }
  11.  
  12. public static boolean checkIfURLExists(String targetUrl) {
  13. HttpURLConnection httpUrlConn;
  14. try {
  15. httpUrlConn = (HttpURLConnection) new URL(targetUrl).openConnection();
  16. httpUrlConn.setRequestMethod("HEAD");
  17. httpUrlConn.setConnectTimeout(30000);
  18. httpUrlConn.setReadTimeout(30000);
  19. return (httpUrlConn.getResponseCode() == HttpURLConnection.HTTP_OK);
  20. } catch (Exception e) {
  21. System.out.println("Error: " + e.getMessage());
  22. return false;
  23. }
  24. }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement