Sending GET request with Authentication headers using restTemplate

前端 未结 6 1361
执念已碎
执念已碎 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:42

    You're not missing anything. RestTemplate#exchange(..) is the appropriate method to use to set request headers.

    Here's an example (with POST, but just change that to GET and use the entity you want).

    Here's another example.

    Note that with a GET, your request entity doesn't have to contain anything (unless your API expects it, but that would go against the HTTP spec). It can be an empty String.

提交回复
热议问题