【发布时间】: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