| | |
| | | |
| | | /** |
| | | * 执行GET请求 |
| | | * |
| | | * @param url |
| | | * @param paramsMap |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static String doGet(String url,Map<String, String> paramsMap) throws Exception{ |
| | | public static String doGet(String url, Map<String, String> paramsMap) throws Exception { |
| | | CloseableHttpClient client = HttpClients.createDefault(); |
| | | String responseText = ""; |
| | | CloseableHttpResponse response = null; |
| | |
| | | String getUrl = url + "?"; |
| | | if (paramsMap != null) { |
| | | for (Map.Entry<String, String> param : paramsMap.entrySet()) { |
| | | // getUrl += param.getKey() + "=" + URLEncoder.encode(param.getValue(), "UTF-8") + "&"; |
| | | // getUrl += param.getKey() + "=" + URLEncoder.encode(param.getValue(), "UTF-8") + "&"; |
| | | getUrl += param.getKey() + "=" + URLEncoder.encode(param.getValue(), "UTF-8") + "&"; |
| | | } |
| | | } |
| | |
| | | |
| | | HttpEntity entity = response.getEntity(); |
| | | if (entity != null) { |
| | | responseText = EntityUtils.toString(entity,"UTF-8"); |
| | | responseText = EntityUtils.toString(entity, "UTF-8"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("http request failed", e); |
| | | log.error("http request failed--{}", e.getMessage()); |
| | | } finally { |
| | | try { |
| | | response.close(); |
| | | if (null != response) response.close(); |
| | | } catch (Exception e) { |
| | | log.error("", e); |
| | | } |
| | | } |
| | | |
| | | return responseText; |
| | | } |
| | | |