| | |
| | | return response.getBody(); |
| | | } |
| | | |
| | | public static String HttpRestClientByObjectParams(String url, HttpMethod method, MultiValueMap<String, Object> formParams, String getParams,Map<String,String> headerValMap, MediaType mediaType) { |
| | | if (!StringUtils.isEmpty(getParams)) { |
| | | url = url + Constant.QUESTION + getParams; |
| | | } |
| | | SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); |
| | | requestFactory.setConnectTimeout(15*1000); |
| | | requestFactory.setReadTimeout(15*1000); |
| | | RestTemplate client = new RestTemplate(requestFactory); |
| | | client.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8)); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | if (mediaType == null){ |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| | | }else { |
| | | headers.setContentType(mediaType); |
| | | } |
| | | if (headerValMap != null) { |
| | | headers.setAll(headerValMap); |
| | | } |
| | | HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(formParams, headers); |
| | | // 执行HTTP请求 |
| | | ResponseEntity<String> response = client.exchange(url, method, requestEntity, String.class); |
| | | |
| | | return response.getBody(); |
| | | } |
| | | |
| | | public static String getUrlParamsByMap(Map<String, Object> map) { |
| | | if (map == null) { |
| | | return ""; |