1、post请求,参数格式为json
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
httpHeaders.set("Authorization", "Bearer " + token);
HttpEntity<String> configHttpEntity = new HttpEntity<>(JSON.toJSONString(pushParams), httpHeaders);
ResponseEntity<PushResult> pushParamResponseEntity = restTemplate.exchange(pushUrlRC2, HttpMethod.POST, configHttpEntity, PushResult.class);
PushResult body = pushParamResponseEntity.getBody();
2、post请求,表单提交
HttpHeaders tokenHeaders = new HttpHeaders();
tokenHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> tokenParams = new LinkedMultiValueMap<>();
tokenParams.add("client_id", "waterworks");
tokenParams.add("client_secret", "T7D/XSU7hW1_DHqX");
tokenParams.add("grant_type", "password");
tokenParams.add("username", "waterworks");
tokenParams.add("password", "T7D/XSU7hW1_DHqX");
HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(tokenParams, tokenHeaders);
ResponseEntity<JSONObject> toeknResponseEntity = restTemplate.exchange(RCTokenUrl, HttpMethod.POST, httpEntity, JSONObject.class);
JSONObject body = toeknResponseEntity.getBody();