Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top