HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
// 请勿轻易改变此提交方式,大部分的情况下,提交方式都是表单提交
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
JSONObject jsonObj = new JSONObject();
jsonObj.put("uid",sendMessage.getUId());
jsonObj.put("message",sendMessage.getMessage());
jsonObj.put("param",sendMessage.getParam());
// 封装参数,千万不要替换为Map与HashMap,否则参数无法传递
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
HttpEntity<String> requestEntity = new HttpEntity<String>(jsonObj.toString(), headers);
// 执行HTTP请求
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);