String url = "";
String bodyStr ="";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Accept", MediaType.APPLICATION_JSON.toString()); <------重点
httpHeaders.add("Content-Type", MediaType.APPLICATION_JSON.toString()); <------重点
HttpEntity<String> httpEntity = new HttpEntity<>(bodyStr, httpHeaders);
ResponseEntity<String> responseEntity =
restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
String responseBody = String.valueOf(responseEntity.getBody());