List of usage examples for org.apache.commons.httpclient.methods GetMethod setQueryString
public void setQueryString(String queryString)
From source file:zz.pseas.ghost.utils.HttpClinetUtil.java
/** * @author GS/*from ww w.java 2 s . c o m*/ * @param url * @param para * @param cookie * @return * @throws IOException */ public static String get(String url, Map<String, String> para, String cookie) throws IOException { String responseBody = null; GetMethod getMethod = new GetMethod(url); getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ???? NameValuePair[] data = new NameValuePair[para.size()]; int index = 0; for (String s : para.keySet()) { data[index++] = new NameValuePair(s, para.get(s)); // ?? } getMethod.setQueryString(data); // ? 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; }