Adding authorization to the headers

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

    I struggled with this. I kept getting an error saying "invalid format" because I have a custom implementation and the Authorization header is validated against certain standards. Adding the header this way however worked:

    var http = new HttpClient();
    http.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "key=XXX");
    

提交回复
热议问题