gpt4 book ai didi

c# - 请求通过代理时出现身份验证错误

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

我有以下代码通过代理服务器发出 Web 请求。我在服务器上用wireshark嗅探了网络流量,发现在发出请求时出现了如下错误:

无法验证您的凭据:“缺少凭据。”。在验证您的凭据之前,您将不会被允许访问。\n

身份验证应该通过 NTLM 运行。

有人可以帮忙吗?

    //... CALL THE CODE
string url = String.Format("http://currencyconverter.kowabunga.net/converter.asmx/GetCultureInfo?Currency={0}", CurrencyTo.Text);
returnValue = GetResponseValue(url);
//...

private static string GetResponseValue(string url)
{
WebRequest request = InitialiseWebRequest(url);

WebResponse response = request.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream());

XDocument xmlDoc = new XDocument();
xmlDoc = XDocument.Parse(sr.ReadToEnd());

string returnValue = xmlDoc.Root.Value;
return returnValue;
}

private static WebRequest InitialiseWebRequest(string url)
{
WebRequest request = WebRequest.Create(url);

if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["proxyLogin"]))
{
string proxyUrl = ConfigurationSettings.AppSettings["proxyUrl"];

if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["proxyPort"]))
{
proxyUrl += ":" + ConfigurationSettings.AppSettings["proxyPort"];
}

WebProxy proxy = new WebProxy(proxyUrl);

// Create a NetworkCredential object and associate it with the Proxy property of request object.
proxy.Credentials = new NetworkCredential(ConfigurationSettings.AppSettings["proxyLogin"], ConfigurationSettings.AppSettings["proxyPassword"]);

NetworkCredential networkCredential = new NetworkCredential(ConfigurationSettings.AppSettings["proxyLogin"], ConfigurationSettings.AppSettings["proxyPassword"]);

CredentialCache credentialCache = new CredentialCache();

credentialCache.Add(new Uri(url), "NTML", networkCredential);

request.Credentials = credentialCache;
request.Proxy = proxy;

return request;
}

return request;
}

最佳答案

事实证明,用户名带有域前缀,密码已过期且未在配置中更新。

经过一整天的审视,我灵光一现。

关于c# - 请求通过代理时出现身份验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8036690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com