简体   繁体   English

使用HttpClient时HttpResponseMessage缺少标头,但提琴手找到了

[英]HttpResponseMessage missing headers while using HttpClient but fiddler finds it

I am making a simple HttpClient call like this: 我正在像这样进行一个简单的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();
    }
}

I am looking for a custom auth-header on the response but it is missing when I iterate over Headers collection. 我正在寻找响应中的自定义auth-header,但是当我遍历Headers集合时却找不到它。

However, same Http request caught by Fiddler shows the header. 但是, Fiddler捕获的相同Http请求显示了标头。 If I make same request on Postman or any browser, I see the header. 如果我在Postman或任何浏览器上发出相同的请求, Postman看到标题。

Wondering what am I missing here. 想知道我在这里想念什么。

[Update] [更新]

Raw Headers captured on Fiddler by executing same code above: 通过执行上面相同的代码在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

Headers printed by above code: 上面代码打印的标题:

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

I would like to capture the header WWW-Authenticate-Test which is somehow filtered out while it goes through the HttpClient magic. 我想捕获标头WWW-Authenticate-Test ,它通过HttpClient魔术时以某种方式被过滤掉了。

它可能是一个内容标头

response.Content.Headers.Select(header => header.Key).Dump();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Output 从 HttpClient HttpResponseMessage 到控制台的所有标头 - Output all headers from HttpClient HttpResponseMessage to console 使用HttpClient和HttpResponseMessage的带有两个字符串的PostAsync - PostAsync with two strings using HttpClient and HttpResponseMessage HttpClient:使用HttpResponseMessage.Content.ReadAsStreamAsync()时限制响应(下载的文件)大小 - HttpClient: limit response (downloaded file) size while using HttpResponseMessage.Content.ReadAsStreamAsync() 使用HttpClient发布并读取HttpResponseMessage状态 - Post using HttpClient & Read HttpResponseMessage status 如何使用 HttpClient 从缓存中确定 HttpResponseMessage 是否已完成 - How to determine if an HttpResponseMessage was fulfilled from cache using HttpClient HttpClient HttpResponseMessage地址/ URI - HttpClient HttpResponseMessage Address / URI 使用 HTTPClient 调用 REST API 时在 httpResponseMessage 中获取 null - Getting null in httpResponseMessage when calling REST API using HTTPClient 不使用 Fiddler 代理时 C# HttpClient 504 网关超时 - C# HttpClient 504 Gateway Timeout when not using Fiddler proxy 如何在HttpClient中使用Fiddler? - How to use Fiddler with HttpClient? HttpClient不适用于Fiddler - HttpClient does not work with Fiddler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM