0

My code is as follow:

public chkRechable(String hostNameOrIp) {

boolean isRechable = InetAddress.getByName(hostNameOrIp).isReachable(30);
return isRechable;
}

Parameter can be "http://192.168.0.77:8080/ws/api/customer/5" or "http://example.com:8080/ws/api/customer/5"

But everytime it's returning false although I can browse the URL.

ray
  • 4,210
  • 8
  • 35
  • 46
  • Shouldn't you be using `getByAddress` instead of `getByName` for an IP Address? And see if the solution here works: http://stackoverflow.com/a/3584332/450534 – Siddharth Lele Mar 22 '13 at 04:38

1 Answers1

0

What do you mean "reachable"? If "open the page" means "reachable", you can just try to use an HTTP connection to connect to it. If you got exceptions: your net work might down; you cannot connect to the host; Then you shall check the http return code, to see if there are 404 or other errors.

Robin
  • 10,052
  • 6
  • 31
  • 52