怎么判断webservice服务是否可用
2020-09-08 本文已影响0人
裘马轻狂大帅
怎么判断webservice服务是否可用
/**
* 判断URL是否可达
* @param url 待判断的URL
* @return true: 可达 false: 不可达
*/
public static boolean urlIsReach(String url) {
if (url==null) {
return false;
}
try {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
链接过程可以增加时间长度
if (HttpURLConnection.HTTP_OK==connection.getResponseCode()) {
return true;
}
} catch (Exception e) {
return false;
}
return false;
}