Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用HttpClient时HttpResponseMessage缺少标头,但fiddler找到了它_C#_Httpclient - Fatal编程技术网

C# 使用HttpClient时HttpResponseMessage缺少标头,但fiddler找到了它

C# 使用HttpClient时HttpResponseMessage缺少标头,但fiddler找到了它,c#,httpclient,C#,Httpclient,我正在做一个简单的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.G

我正在做一个简单的
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头,但是当我迭代
集合时,它丢失了

但是,
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
我想捕获标题
WWW Authenticate Test
,它在通过
HttpClient
magic时以某种方式被过滤掉。

它可能是:


不,响应没有正文,我已经验证了内容标题。您可以更新您的问题以包括您在Fiddler中看到的标题吗?我们将能够创建复制品…经过更多研究,我意识到
HttpClient
在出现重定向时从响应中删除auth标题(出于安全考虑)。因此,解决方案似乎是将服务器修复为返回200而不是302/301
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
response.Content.Headers.Select(header => header.Key).Dump();