Is it possible to check the availability of a web site using JAVA other than InetAddress.isReachable ()? InetAddress.isReachable () always returns false.
4 answers
I do not know how it will help / not help, but I will describe my simple train of thought, in a more specific case for android. And so we need to connect to some server and get an answer from it, of course, first you want to check its availability, first you want to write a method, a class, put a check for it (taking into account the fact that you didn’t miss anything, gave rights to the manifest etc.), BUT at this moment you need to ask a question - WHY DOES IT? after a little thought, it turns out to be superfluous, since it does not matter to you to know whether there are connections or not (if this is not a trivial, specific task to check the connection), you need an answer from the server, you get an extra check, since you send the request and option 1 - everything is good and you get an answer, 2 - you get an answer that there is no access, 3 - you take off an error, that there is no connection, you get option 3 discards the verification question.
- Yes, it is logical, but it was unacceptable to wait so long, now I used HttpParams and reduced the time to two seconds. - DeMoGargon
No one bothers to implement handles work through sockets. Just connect to port 80 and send something in the style of "GET /index.html HTTP / 1.1nn" and wait for an answer. If the answer does not come in a reasonable time - considers that the web site is not available. What is considered an acceptable time? it all depends on you. Maybe 1 second will be a lot, and maybe a minute will be short.
If you write the monitoring utility of your server, you can refer to your page. But then probably already use ready-made classes for working with http from org.apache.
Try this Java Network Commands .
for example:
DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet("http://url.com"); HttpResponse response = httpClient.execute(request); int responseCode = response.getStatusLine().getStatusCode(); if(responseCode==200){ // url найден }