设置HttpClient的授权头 [英] Setting Authorization Header of HttpClient
本文介绍了设置HttpClient的授权头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用于 REST API 的 HttpClient.但是我在设置 Authorization 标头时遇到了问题.我需要将标头设置为我从执行 OAuth 请求中收到的令牌.我看到了一些 .NET 代码,建议如下,
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 doing my OAuth request. I saw some code for .NET that suggests the following,
httpClient.DefaultRequestHeaders.Authorization = new Credential(OAuth.token);
但是,WinRT 中不存在 Credential 类.有人对如何设置授权标头有任何想法吗?
However the Credential class does that not exist in WinRT. Anyone have any ideas how to set the Authorization header?
推荐答案
所以做法如下,
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", "Your Oauth token");
这篇关于设置HttpClient的授权头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文