// null = online, Throwable = offline public static Throwable checkIfHttpServerIsOnline(String serverName) { try { String url = serverName.startsWith("http") ? serverName : "http://" + serverName + "/"; //HttpURLConnection.setFollowRedirects(false); // note : you may also need // HttpURLConnection.setInstanceFollowRedirects(false) HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod("HEAD"); int responseCode = con.getResponseCode(); //print("Response code for " + url + ": " + responseCode); // If we came this far, assume server is online. return null; //return (con.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { return e; } }
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001114 |
Snippet name: | checkIfHttpServerIsOnline |
Eternal ID of this version: | #1001114/1 |
Text MD5: | d4fd9e46fdbd0440578dedf0f9d31c07 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-09-22 18:04:28 |
Source code size: | 833 bytes / 20 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 681 / 901 |
Referenced in: | [show references] |