Setting Authorization Header of HttpClient

前端 未结 21 2262
粉色の甜心
粉色の甜心 2020-11-22 14:53

I have an HttpClient that I am using for a REST API. However I am having trouble setting up the Authorization header. I need to set the header to the token I received from d

21条回答
  •  再見小時候
    2020-11-22 15:38

    As it is a good practice to reuse the HttpClient instance, for performance and port exhaustion problems, and because none of the answers give this solution (and even leading you toward bad practices :( ), I put here a link towards the answer I made on a similar question :

    https://stackoverflow.com/a/40707446/717372

    Some sources on how to use HttpClient the right way:

    • https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
    • https://blogs.msdn.microsoft.com/alazarev/2017/12/29/disposable-finalizers-and-httpclient/

提交回复
热议问题