1 public static int testWsdlConnection(String address) throws Exception { 2 int status = 404; 3 try { 4 URL urlObj = new URL(a ...
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 }
原标题:Java 测试URL地址是否能正常连接
关键词:JAVA
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。