我必须将凭据缓存中的用户名和密码分配给 Httpwebrequest。当我分配给缓存时,它正在工作,但是从缓存中分配给 Webrequest 时,它显示为空。我哪里错了?
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;