httpclient4

if (urls.size() > 0) {

            HttpClient httpClient = null;

            httpClient = SimpleHttpsTrustClientTemplate.createHttpClient();

            HttpGet httpGet = new HttpGet();

            HttpResponse response = null;

            for (Iterator<String> iter = urls.iterator(); iter.hasNext();) {

                httpGet.setURI(URI.create(iter.next()));

                try {

                    response = httpClient.execute(httpGet);

                    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NOT_FOUND) {

                        iter.remove();

                    }

                } catch (ClientProtocolException e) {

                    LOGGER.error(e);

                } catch (IOException e) {

                    LOGGER.error(e);

                } finally {

                    try {

                        if (response != null) {

                            response.getEntity().getContent().close();

                        }

                    } catch (IllegalStateException e) {

                        LOGGER.error(e);

                    } catch (IOException e) {

                        LOGGER.error(e);

                    }

                }

            }

        }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章