本文介绍了设置的HttpClient的认证头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个HttpClient的,我使用使用REST API。但是我有麻烦建立Authorization头。我需要设置的头,我从做我的OAuth请求收到的令牌。
我看到了一些.NET code,它提出以下建议,
I have a HttpClient that I am using to use 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 doing my OAuth request.I saw some code for .NET that suggests the following,
httpClient.DefaultRequestHeaders.Authorization = new Credential(OAuth.token);
然而凭证类这是否不存在WinRT中。任何人有任何想法如何设置授权头?
However the Credential class does that not exist in WinRT. Anyone have any ideas how to set the Authorization header?
推荐答案
因此,要做到这一点是以下内容的方式,
So the way to do it is the following,
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Your Oauth token");
这篇关于设置的HttpClient的认证头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!