我正在做一个简单的 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();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找响应中的自定义 auth-header,但是当我遍历Headers集合时它丢失了。
但是,同样的 Http 请求被 Fiddler显示了标头。如果我在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
Run Code Online (Sandbox Code Playgroud)
上面代码打印的标题:
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
Run Code Online (Sandbox Code Playgroud)
我想捕获WWW-Authenticate-Test在它通过HttpClient魔法时以某种方式过滤掉的标题。
这可能是一个内容标题:
response.Content.Headers.Select(header => header.Key).Dump();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
654 次 |
| 最近记录: |