Java简单判断webservice的wsdl是否可达(网络是否连通)
import java.net.HttpURLConnection;
import java.net.URL;
public class TestWebservice {
public static void main(String[] args) {
String url = "http://192.168.129.15:8088/NationTransService/webservice/nationalService?wsdl";
urlIsReach(url);
}
public static boolean urlIsReach(String url) {
if (url == null) {
System.out.println("输入的url为空!");
return false;
}
try {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
if (HttpURLConnection.HTTP_OK == connection.getResponseCode()) {
System.out.println("网络联通!");
return true;
}
} catch (Exception e) {
System.out.println("网络不通!");
return false;
}
System.out.println("网络不通!");
return false;
}
}