1 public static int testWsdlConnection(String address) throws Exception { 2 int status = 404; 3 try { 4 URL urlObj = new URL(address); 5 HttpURLConnection oc = (HttpURLConnection) urlObj.openConnection(); 6 oc.setUseCaches(false); 7 oc.setConnectTimeout(3000); // 设置超时时间 8 status = oc.getResponseCode();// 请求状态 9 if (200 == status) { 10 // 200是请求地址顺利连通。。 11 return status; 12 } 13 } catch (Exception e) { 14 e.printStackTrace(); 15 throw e; 16 } 17 return status; 18 }
定义了一个int型,如果返回可200则是地址能成功连通,如果返回0或者其他则是失败