2011-11-07 37 views
2

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

当你嗅探,你有没有注意到,如果正确的凭据(用户名/密码,我猜是你如何验证)去代理? – zmilojko

+0

我该如何去检查这个?由于安全原因,我认为不可能检查用户名/密码 – Burt

回答

0

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

经过整整一天看过去的明显我有一个灯泡的时刻。

相关问题