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

RestTemplate 携带header 发送get请求

程序员文章站 2022-06-25 19:20:34
...

 

String url = "www.csdn.net"
HttpHeaders headers = new HttpHeaders();

headers.put("Content-Type", Collections.singletonList("application/json;charset=UTF-8"));
headers.add("Authorization", "abc");

HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
ResponseEntity<String> resEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);