我正在进行一个简单的HttpClient
调用:
Uri basePath = new Uri("https://my-host.com/");
string path = "api/my-path";
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = basePath;
HttpResponseMessage response = await httpClient.GetAsync(path);
if (response.IsSuccessStatusCode)
{
response.Headers.Select(header => header.Key).Dump();
}
}
我正在寻找响应的自定义auth-header,但是当我遍历Headers
集合时,它会丢失。
然而,Fiddler
捕获的相同Http请求显示了标头。
如果我在Postman
或任何浏览器上发出相同的请求,我会看到标题。
想知道我在这里失踪了什么。
[更新]
通过执行上述相同代码在Fiddler
上捕获的原始标题:
HTTP/1.1 302 Found
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Location: <redacted>
Server: Microsoft-IIS/8.0
WWW-Authenticate-Test: <redacted>
X-AspNet-Version: 4.0.30319
Set-Cookie: <redacted>
X-UA-Compatible: IE=edge
Date: Sat, 11 Nov 2017 23:15:19 GMT
Content-Length: 0
上面代码打印的标题:
Pragma
Strict-Transport-Security
X-Content-Type-Options
X-Frame-Options
x-ms-request-id
Cache-Control
P3P
Set-Cookie
Server
X-Powered-By
Date
我想捕获标题WWW-Authenticate-Test
,它会在HttpClient
魔法通过时以某种方式过滤掉。
答案 0 :(得分:3)
可能是content header:
response.Content.Headers.Select(header => header.Key).Dump();