@Autowired
private RestTemplate restTemplate;
public void postRequest(Student student){
String url = "localhost:8001/student/save";
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Student> httpEntity = new HttpEntity<>(student, httpHeaders);
ResponseEntity response = restTemplate.postForObject(url, httpEntity, ResponseEntity.class);
log.info("response:",response);
}
public void getRequest(Integer id){
String url = "localhost:8001/student/findById/id=" + id;
HttpHeaders httpHeaders = new HttpHeaders();
ResponseEntity response = restTemplate.getForObject(url,ResponseEntity.class);
log.info("response:",response);
}
RestTemplate发送请求
最新推荐文章于 2024-10-01 09:29:45 发布