Sending GET request with Authentication headers using restTemplate

前端 未结 6 1366
执念已碎
执念已碎 2021-01-31 01:20

I need to retrieve a resources from my server by sending a GET request with the some Authorization headers using RestTemplate.

After going over the docs I noticed that

6条回答
  •  情话喂你
    2021-01-31 01:49

    These days something like the following will suffice:

    HttpHeaders headers = new HttpHeaders();
    headers.setBearerAuth(accessToken);
    restTemplate.exchange(RequestEntity.get(new URI(url)).headers(headers).build(), returnType);
    

提交回复
热议问题