当请求通过代理时,身份验证错误

本文关键字:身份验证 错误 代理 请求 | 更新日期: 2023-09-27 18:13:46

我有以下代码,通过代理服务器发出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;
    }

当请求通过代理时,身份验证错误

原来用户名有域名前缀,密码过期,没有在配置中更新。

一整天都在看那些显而易见的东西,我灵光一现