【问题标题】:Authentication error when requests go through proxy请求通过代理时的身份验证错误
【发布时间】:2011-11-07 12:44:31
【问题描述】:

我有以下代码通过代理服务器发出网络请求。我在服务器上用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# asp.net .net networking proxy


【解决方案1】:

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

经过一整天的观察,我得到了一个灯泡时刻。

【讨论】:

    猜你喜欢
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    相关资源
    最近更新 更多