public static String httpGet(String url,MapheaderMap) { String result = null; HttpClient httpClient = new DefaultHttpClient(); try { HttpGet httpGet = new HttpGet(url); if (headerMap != null) { for (String key : headerMap.keySet()) { httpGet.addHeader(key, headerMap.get(key).toString()); } } HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); result = EntityUtils.toString(httpEntity, "UTF-8"); EntityUtils.consume(httpEntity); } catch (ClientProtocolException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } finally { httpClient.getConnectionManager().shutdown(); } return result; } public static String httpPost(String url, String data,Map headerMap) { String result = null; HttpClient httpClient = new DefaultHttpClient(); try { HttpPost httpPost = new HttpPost(url); if (headerMap != null) { for (String key : headerMap.keySet()) { httpPost.addHeader(key, headerMap.get(key).toString()); } } httpPost.setEntity(new StringEntity(data, "UTF-8")); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); result = EntityUtils.toString(httpEntity); EntityUtils.consume(httpEntity); } catch (ClientProtocolException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } finally { httpClient.getConnectionManager().shutdown(); } return result; }



