List of usage examples for org.apache.commons.httpclient.params HttpMethodParams RETRY_HANDLER
String RETRY_HANDLER
To view the source code for org.apache.commons.httpclient.params HttpMethodParams RETRY_HANDLER.
Click Source Link
From source file:zz.pseas.ghost.utils.HttpClinetUtil.java
/** * @author GS/*from w w w . j av a2 s . c om*/ * @param url * @param para * @param cookie * @return * @throws IOException */ public static String get(String url, String cookie) throws IOException { String responseBody = null; GetMethod getMethod = new GetMethod(url); getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ???? if (!cookie.equals("")) { getMethod.setRequestHeader("cookie", cookie); } try { int statusCode = hc.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { LOG.error("Method failed: " + getMethod.getStatusLine()); } responseBody = getMethod.getResponseBodyAsString(); } catch (UnknownHostException e) { e.printStackTrace(); LOG.error("??" + e.getMessage()); } catch (HttpException e) { // ? e.printStackTrace(); LOG.error("?" + e.getMessage()); } catch (IOException e) { // ? e.printStackTrace(); LOG.error("?" + e.getMessage()); } finally { getMethod.releaseConnection(); // } return responseBody; }
From source file:zz.pseas.ghost.utils.HttpClinetUtil.java
/** * @author GS// ww w . j a v a 2 s . c o m * @param url * @param headers * @return * @throws IOException */ public static String get(String url, Header[] headers) throws IOException { String responseBody = null; GetMethod getMethod = new GetMethod(url); getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ???? for (Header h : headers) { getMethod.addRequestHeader(h); } try { int statusCode = hc.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { LOG.error("Method failed: " + getMethod.getStatusLine()); } responseBody = getMethod.getResponseBodyAsString(); } catch (SocketTimeoutException e) { e.printStackTrace(); LOG.error("??" + e.getMessage()); } catch (UnknownHostException e) { e.printStackTrace(); LOG.error("??" + e.getMessage()); } catch (HttpException e) { // ? e.printStackTrace(); LOG.error("?" + e.getMessage()); } catch (IOException e) { // ? e.printStackTrace(); LOG.error("?" + e.getMessage()); } finally { getMethod.releaseConnection(); // } return responseBody; }
From source file:zz.pseas.ghost.utils.HttpClinetUtil.java
/** * HTTP??// w w w. ja v a 2 s .c o m * * @author GS * @param url * @param para * @param cookie * @return * @throws IOException */ public static int getStatusCode(String url, String cookie) throws IOException { GetMethod getMethod = new GetMethod(url); getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ???? if (!cookie.equals("")) { getMethod.setRequestHeader("cookie", cookie); } int statusCode = 0; try { statusCode = hc.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { LOG.error("Method failed: " + getMethod.getStatusLine()); } } catch (SocketTimeoutException e) { e.printStackTrace(); LOG.error("??" + e.getMessage()); } catch (UnknownHostException e) { e.printStackTrace(); LOG.error("??" + e.getMessage()); } catch (HttpException e) { // ? e.printStackTrace(); LOG.error("?" + e.getMessage()); } catch (IOException e) { // ? e.printStackTrace(); LOG.error("?" + e.getMessage()); } finally { getMethod.releaseConnection(); // } return statusCode; }