@@ -315,7 +315,7 @@ public static boolean isHostReachable(String hostUrl) {
315
315
hostUrl = "http://" + hostUrl ;
316
316
317
317
boolean isReachable = false ;
318
- boolean isExceptionHappens = false ;
318
+ // boolean isExceptionHappens = false;
319
319
try {
320
320
final URL url = new URL (hostUrl );
321
321
final HttpURLConnection httpURLConnection = (HttpURLConnection ) url .openConnection ();
@@ -324,19 +324,22 @@ public static boolean isHostReachable(String hostUrl) {
324
324
httpURLConnection .setConnectTimeout (TIME_OUT ); // Timeout in seconds
325
325
httpURLConnection .connect ();
326
326
final int responseCode = httpURLConnection .getResponseCode ();
327
- isReachable = responseCode == HttpURLConnection .HTTP_OK //200
328
- || responseCode == HttpURLConnection .HTTP_BAD_METHOD
329
- || responseCode == HttpURLConnection .HTTP_BAD_REQUEST
330
- || responseCode == HttpURLConnection .HTTP_ACCEPTED
331
- || responseCode == HttpURLConnection .HTTP_FORBIDDEN
332
- || responseCode == HttpURLConnection .HTTP_UNAUTHORIZED ;
327
+ isReachable = responseCode >0 ;
328
+ // https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
329
+ // there are too many codes, guess checking if its gt 0 is enough
330
+ // == HttpURLConnection.HTTP_OK //200
331
+ // || responseCode == HttpURLConnection.HTTP_BAD_METHOD
332
+ // || responseCode == HttpURLConnection.HTTP_BAD_REQUEST
333
+ // || responseCode == HttpURLConnection.HTTP_ACCEPTED
334
+ // || responseCode == HttpURLConnection.HTTP_FORBIDDEN
335
+ // || responseCode == HttpURLConnection.HTTP_UNAUTHORIZED;
333
336
334
337
} catch (MalformedURLException e ) {
335
- isExceptionHappens = true ;
336
- Log .e ("ServerChecker" , e );
338
+ // isExceptionHappens = true;
339
+ // Log.e("ServerChecker", e);
337
340
} catch (IOException e ) {
338
- isExceptionHappens = true ;
339
- Log .e ("ServerChecker" , e );
341
+ // isExceptionHappens = true;
342
+ // Log.e("ServerChecker", e);
340
343
}
341
344
342
345
// // maybe host is not reachable using GET method? Lets try with POST
0 commit comments