Setting Authorization Header of HttpClient

前端 未结 21 2290
粉色の甜心
粉色の甜心 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:14

    I look for a good way to deal with this issue and I am looking at the same question. Hopefully, this answer will be helping everyone who has the same problem likes me.

    using (var client = new HttpClient())
    {
        var url = "https://www.theidentityhub.com/{tenant}/api/identity/v1";
        client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
        var response = await client.GetStringAsync(url);
        // Parse JSON response.
        ....
    }
    

    reference from https://www.theidentityhub.com/hub/Documentation/CallTheIdentityHubApi

提交回复
热议问题