我试图调试一些HttpClient身份验证问题,所以我有:
var handler = new MyHttpClientHandler { Credentials = new NetworkCredential("myun", "mypw") };
using (var client = new HttpClient(handler))
{
await client.GetStringAsync("https://httpbin.org/digest-auth/auth/myun/mypw");
}
其中:
public class MyHttpClientHandler : HttpClientHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var result = base.SendAsync(request, cancellationToken);
return result;
}
}
但SendAsync()只被命中一次,其中看到请求包含没有身份验证详细信息的原始请求,结果包含成功身份验证的最终200响应。我怎样才能看到最初的401质询和后续请求,其中包含必须在中间发生的凭证?