3

我正在尝试HttpClient在 .NET 5 中进行摘要身份验证以与 mongoDB Atlas 一起使用。.Net Core HttpClient Digest Authentication中建议的解决方法不再适用于 .NET 5。

例如,这段代码

AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
var httpClient = new HttpClient(
            new HttpClientHandler
            {
                Credentials =
                    new NetworkCredential(
                        userName,
                        password)
            });
var domain = "https://cloud.mongodb.com/";
var response = httpClient.GetAsync(new Uri($"{domain}api/atlas/v1.0/groups/{groupId}")).Result;
        

当目标框架是 .net core 3.1 时返回 200 ok 并返回正确的数据

但是当目标框架是 .NET 5 http 客户端时,不要在后台处理摘要流并返回

StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  WWW-Authenticate: Digest realm="MMS Public API", domain="", nonce=""generatedNonce"", algorithm=MD5, qop="auth", stale=false
  x-envoy-upstream-service-time: 2
  Date: Sun, 17 Jan 2021 13:37:12 GMT
  Server: envoy
  Content-Type: application/json
  Content-Length: 106
} 

有谁知道我除了自己实现摘要流程之外还有其他选择吗?

4

0 回答 0