| | |
| | | |
| | | return EntityUtils.toString(entity, StaticData.TEXT_ENCODER); |
| | | } catch (Exception ex) { |
| | | log.error(ex); |
| | | log.error(ex.getMessage(), ex); |
| | | |
| | | return getErrorInfo(uri, ex); |
| | | } |
| | |
| | | httpPost.setEntity(postEntity); |
| | | |
| | | CloseableHttpResponse closeResponse = httpClient.execute(httpPost); |
| | | |
| | | // 取出返回体 |
| | | HttpEntity entity = closeResponse.getEntity(); |
| | | |
| | | return EntityUtils.toString(entity, StaticData.TEXT_ENCODER); |
| | | } catch (Exception ex) { |
| | | log.error(ex); |
| | | log.error(ex.getMessage(), ex); |
| | | |
| | | return getErrorInfo(uri, ex); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Get请求-RestTemplate |
| | | * |
| | | * @param uri Uri地址 |
| | | * @return 响应字符串 |
| | | * GET请求(REST) |
| | | */ |
| | | public static String getForRest(String uri) { |
| | | try { |
| | | RestTemplate rest = getRestTemplate(); |
| | | RestTemplate rest = getRestTemplate(); |
| | | |
| | | return rest.getForObject(uri, String.class); |
| | | } catch (Exception ex) { |
| | | log.error(ex); |
| | | |
| | | return getErrorInfo(uri, ex); |
| | | } |
| | | return rest.getForObject(uri, String.class); |
| | | } |
| | | |
| | | /** |
| | | * Post请求-RestTemplate |
| | | * |
| | | * @param uri Uri地址 |
| | | * @param postData 待发送数据 |
| | | * @return 响应字符串 |
| | | * POST请求(REST) |
| | | */ |
| | | public static String postForRest(String uri, List<NameValuePair> postData) { |
| | | try { |
| | | RestTemplate rest = getRestTemplate(); |
| | | UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postData, StaticData.TEXT_ENCODER); |
| | | public static String postForRest(String uri, Map<String, Object> map) { |
| | | RestTemplate rest = getRestTemplate(); |
| | | |
| | | return rest.postForObject(uri, entity, String.class); |
| | | } catch (Exception ex) { |
| | | log.error(ex); |
| | | return rest.postForObject(uri, map, String.class); |
| | | } |
| | | |
| | | return getErrorInfo(uri, ex); |
| | | } |
| | | /** |
| | | * POST请求(REST) |
| | | */ |
| | | public static <T> String postForRest(String uri, List<T> list) { |
| | | RestTemplate rest = getRestTemplate(); |
| | | |
| | | return rest.postForObject(uri, list, String.class); |
| | | } |
| | | |
| | | /** |