帮我写一个RestTemplate post的程序吧
时间: 2023-03-06 18:17:21 浏览: 75
java利用springboot提供的RestTemplate爬虫示例
5星 · 资源好评率100%
我可以给你一个RestTemplate post的示例代码:String url = "http://example.com/resource";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
阅读全文