在 .Net Core 3.1 应用程序中使用 Mongo Atlas API,但是我无法让
这是我收到的响应。
HttpClient
处理 Digest 验证的挑战。代码发送第一个请求,获取 401 响应,然后不会重新发送带有适当身份验证的请求。
以下是我一直在尝试让其工作的代码:var domain = "https://cloud.mongodb.com/";
var credCache = new CredentialCache();
credCache.Add(new Uri(domain),"Digest", new NetworkCredential(user,secret));
var httpClient = new HttpClient( new HttpClientHandler { Credentials = credCache});
var answer = await httpClient.GetAsync(new Uri($"{domain}api/atlas/v1.0/groups/{groupId}/databaseUsers"));
这是我收到的响应。
StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Mon, 27 Jan 2020 21:03:14 GMT
WWW-Authenticate: Digest realm="MMS Public API", domain="", nonce="generatedNonce", algorithm=MD5, qop="auth", stale=false
Content-Type: application/json
Content-Length: 106
}
我已经成功地发送了curl请求,因此我确信我的用户名/密码/组是正确的。
有没有人在这段代码中看到什么问题,或者知道我可以做些什么来进一步调试这个问题?