httpclient检查某个链接是否可用
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; }
点亮测试人生!QQ:408129370
百度阅读电子书地址:http://yuedu.baidu.com/ebook/f6dbb2a2f01dc281e53af0f3
讨论QQ群:536192476
个人公众号:
百度阅读电子书地址:http://yuedu.baidu.com/ebook/f6dbb2a2f01dc281e53af0f3
讨论QQ群:536192476
个人公众号: