-3

I'm doing an app that connect to a server, this service uptime is not 100% so I need make an status checker.

My idea is call a php from Java and recover a "0" if is not active and "1" if the service is running and don't waste time of the app users.

Any idea how can I do that in Java?

Greetens and thanks

Toux
  • 100
  • 3
  • 8

1 Answers1

0

An easier method might be to do a HTTP HEAD instead of an HTTP GET. It does not request any content.

HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con =
    (HttpURLConnection) new URL(urlpath).openConnection();
con.setUsesCache(false); // Of course.
con.setRequestMethod("HEAD");
boolean isOnAir = con.getResponseCode() == HttpURLConnection.HTTP_OK;
con.disconnect();
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138