Adding authorization to the headers

前端 未结 5 1362
悲&欢浪女
悲&欢浪女 2020-12-09 03:03

I have the following code:

...
AuthenticationHeaderValue authHeaders = new AuthenticationHeaderValue(\"OAuth2\", Contract.AccessToken);
string result = await         


        
5条回答
  •  半阙折子戏
    2020-12-09 03:30

    In your code you are doing this:

    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"{token}");
    

    I think the following should work the same manner without using string interpolation:

    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    

    This is because the string interpolation is just generating a string with the token in it!

提交回复
热议问题