[英]Digest authentication in Windows Store app using HttpClient (C#)
I'm struggling with this problem for a week. 我在这个问题上挣扎了一个星期。 I have to use API with Digest authentication in Windows Store App, but while I'm using this code I get System.ArgumentNullException in this line of code:
我必须在Windows Store App中将API与摘要身份验证一起使用,但是当我使用此代码时,在以下代码行中得到System.ArgumentNullException:
HttpHandler.Credentials = credCache;
Here is rest of code: 这是其余的代码:
var credCache = new CredentialCache();
credCache.Add(new Uri("https://myserverIP/api"),"Digest",new NetworkCredential("mylogin", "mypassword") );
var HttpHandler = new HttpClientHandler();
HttpHandler.Credentials = credCache;
var httpClient = new HttpClient(HttpHandler);
var answer = await httpClient.GetAsync(new Uri("https://myserverIP/api/?function=someKindOfFunction"));
answer.EnsureSuccessStatusCode();
What am I doing wrong? 我究竟做错了什么?
A quick fix to your issue is to use credCache.GetCredentials()
instead of just credCache
when assigning a value to HttpHandler. 将问题分配给HttpHandler时,快速解决此问题的方法是使用
credCache.GetCredentials()
而不是credCache
。 Credentials as such: 这样的凭证:
var credCache = new CredentialCache();
credCache.Add(new Uri("https://myserverIP/api"),"Digest",new NetworkCredential("mylogin", "mypassword") );
var HttpHandler = new HttpClientHandler();
HttpHandler.Credentials = credCache.GetCredential(new Uri("https://myserverIP/api"), "Digest");
This works without the ArgumentNullException
. 这可以在没有
ArgumentNullException
情况下工作。
Hope this helps. 希望这可以帮助。
Thanks, Sid 谢谢,席德
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.