当使用添加页眉httpClient.GetAsync [英] Adding headers when using httpClient.GetAsync
本文介绍了当使用添加页眉httpClient.GetAsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
林落实与Apiary.io其他的同事做了一个API,在Windows商店应用项目。
Im implementing a api made by other collegues with Apiary.io, in a windows store app project.
他们表现出的方法我要实现的这个例子
they show this example of a method i have to implement
var baseAddress = new Uri("https://private-a8014-xxxxxx.apiary-mock.com/");
using (var httpClient = new HttpClient{ BaseAddress = baseAddress })
{
using(var response = await httpClient.GetAsync("user/list{?organizationId}"))
{
string responseData = await response.Content.ReadAsStringAsync();
}
}
在此和其他一些方法,我需要有一个记号,我之前
in this and some other methods i need to have a header with a token that i get before
继承人邮差(Chrome扩展)的图像与头IM谈论
的标题
heres a image of postman( chrome extension ) with the header im talking about
我怎么了授权头添加到?要求
how do i add that Authorization header to the request?
推荐答案
您将它们添加到HttpClient的,像这样:
You add them to httpclient like so:
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Your Oauth token");
下面是详细的SO的答案
这篇关于当使用添加页眉httpClient.GetAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文