2011-11-07 61 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

原來的用戶名有前綴域與密碼過期,在配置沒有更新。

經過整整一天看過去的明顯我有一個燈泡的時刻。

相關問題