0
我的代碼如下:的Android如何檢查URL名稱或IP是rechable
public chkRechable(String hostNameOrIp) {
boolean isRechable = InetAddress.getByName(hostNameOrIp).isReachable(30);
return isRechable;
}
參數可以是"http://192.168.0.77:8080/ws/api/customer/5"
或"http://example.com:8080/ws/api/customer/5"
但每次它返回假的,雖然我可以瀏覽URL。
您不應該使用'getByAddress'而不是'getByName'作爲IP地址嗎?看看這裏的解決方案是否工作:http://stackoverflow.com/a/3584332/450534 – 2013-03-22 04:38:33