我正在进行一个简单的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();
}
}
我正在寻找响应中的自定义认证头,但在迭代
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
处理时被一些方式过滤掉了。
HttpClient
在重定向时会从响应中剥离授权头(出于安全考虑)。因此,解决方案似乎是修复服务器以返回200而不是302/301。 - Amit