标签:
private boolean checkUrlIsValid(String url) { CloseableHttpClient httpClient = HttpClients.createDefault(); RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(5000) .build(); HttpGet httpGet = new HttpGet(url); httpGet.setConfig(requestConfig); CloseableHttpResponse response = null; boolean isValid = false; try { response = httpClient.execute(httpGet); int statusCode = response.getStatusLine().getStatusCode(); if(statusCode == 200) { isValid = true; } } catch (Exception e) { } finally { if(response != null) { try { response.close(); } catch (IOException e) { } } } return isValid; }
标签:
原文地址:http://www.cnblogs.com/zhangfei/p/4728182.html