RestTemplate实现PUT请求有返回值

120 阅读1分钟
//设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

//请求实体类 json封装  bodyJson这个是封装的参数  也可以是Map封装
HttpEntity putBodyJson = new HttpEntity(bodyJson,headers);

//发送PUT请求
ResponseEntity<String> responseEntity = restTemplate.exchange("http://127.0.0.1:7001/user/test-http-put", HttpMethod.PUT, putBodyJson, String.class);

strReturn = responseEntity.getBody();