Created
April 15, 2022 08:43
-
-
Save massimilianochiodi/122c55244ddb63cbe23b9c2f3ec91d63 to your computer and use it in GitHub Desktop.
Verify if internet address is reachable
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
public boolean AddressReachable(String hostUrl) { | |
try { | |
URL url = new URL(hostUrl); | |
final HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); | |
urlc.setRequestProperty("User-Agent", "Android Application"); | |
urlc.setRequestProperty("Connection", "close"); | |
urlc.setConnectTimeout(10 * 1000); | |
urlc.connect(); | |
// Fix per connessione con certificato | |
if (urlc.getResponseCode() == 200 || urlc.getResponseCode() == 403) { | |
return true; | |
} | |
} catch (Throwable e) { | |
e.printStackTrace(); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment