Amit
Amit

Reputation: 26316

HttpResponseMessage missing headers while using HttpClient but fiddler finds it

I am making a simple HttpClient call like this:

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.

However, same Http request caught by Fiddler shows the header. If I make same request on Postman or any browser, I see the header.

Wondering what am I missing here.

[Update]

Raw Headers captured on Fiddler by executing same code above:

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.

Upvotes: 6

Views: 1801

Answers (1)

RB.
RB.

Reputation: 37222

It's probably a content header:

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

Upvotes: 10

Related Questions