restTemplate添加请求头

//请求添加token头
HttpHeaders headers = new HttpHeaders();
headers.add("token",token);
HttpEntity requestEntity = new HttpEntity<>(null, headers);
ResponseEntity resEntity = restTemplate.exchange(url.toString(), HttpMethod.GET, requestEntity, String.class);
//请求结果
String str = resEntity.getBody();

你可能感兴趣的:(java)