Adding authorization to the headers

前端 未结 5 1350
悲&欢浪女
悲&欢浪女 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:46

    This line

    client.DefaultRequestHeaders.Authorization = 
               new AuthenticationHeaderValue(authValue.Parameter);
    

    Will produce this header value

    Authorization: ACCESS_TOKEN
    

    Where ACCESS_TOKEN is the value of authValue.Parameter. You want to assign the value you passed instead to get the required header

    client.DefaultRequestHeaders.Authorization = authValue;
    

    Will produce

    Authorization: OAuth2 ACCESS_TOKEN
    

提交回复
热议问题