欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

RestTemplate

程序员文章站 2022-03-02 17:33:13
...
RestTemplate 发送 get 方法

RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new FastJsonHttpMessageConverter());
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
List<MediaType> list = new ArrayList<MediaType>();
list.add(MediaType.TEXT_HTML);
requestHeaders.setAccept(list);
HttpEntity<String> requestEntity = new HttpEntity<String>(null, requestHeaders);
ResponseEntity<Long> response = restTemplate.exchange(sbf.toString(), HttpMethod.GET, requestEntity, Long.class);

return response.getBody();