gpt4 book ai didi

c# - 网络凭据未保存在 CredentialCache 中

转载 作者:太空宇宙 更新时间:2023-11-03 16:26:33 27 4
gpt4 key购买 nike

我必须将凭据缓存中的用户名和密码分配给 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;

最佳答案


你好,您只需要从缓存中检索凭证,然后将其添加到 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

关于c# - 网络凭据未保存在 CredentialCache 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12406566/

27 4 0
文章推荐: ruby-on-rails - Stripe,取消订阅 Ruby on Rails
文章推荐: python - 拥有一个与多个不同模型相关的模型
文章推荐: python - 使用Python CGI显示
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com