[英]Network Credentials not saving in CredentialCache
I have to assign the username and password from credential cache to Httpwebrequest.When i assign to cache it is working but when assigning to Webrequest from cache it shows null. 我必须将凭据缓存中的用户名和密码分配给Httpwebrequest。当我分配给缓存时它正在工作,但是当从缓存分配给Webrequest时它显示为空。 Where i'm wrong?
我哪里错了?
string strServer = "";
strServer = "http://servername/";
Uri uri = new Uri(strServer);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
CredentialCache cache = new CredentialCache();
cache.Add(new Uri(strServer), "Basic", new System.Net.NetworkCredential("username", "password","Domain"));
cache.Add(new Uri(strServer), "Digest", new System.Net.NetworkCredential("username", "password","Domain"));
request.Credentials = cache;
Hello, You just need to retrieve the credential from the cache, and then add it to the web request, example bellow: 您好,您只需要从缓存中检索凭证,然后将其添加到Web请求中,例如下面的示例:
cache.Add(new Uri(strServer), "Basic", new System.Net.NetworkCredential("username", "password","Domain"));
cache.Add(new Uri(strServer), "Digest", new System.Net.NetworkCredential("username", "password","Domain"));
NetworkCredential currentCredentials= cache.GetCredential(new Uri(strServer), "Basic"); //Get specific credential
request.Credentials = currentCredentials; //Allocate credential
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.