怎么判断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;
}
* 判断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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询