【发布时间】:2011-05-20 14:13:52
【问题描述】:
我想读取一些外部 xml,但我必须通过代理连接,但我不知道该怎么做。我有以下代码,xmlurl 包含外部 xml 的路径:
if (content > 0)
{
using (XmlTextReader xml = new XmlTextReader(xmlurl))
{
while (xml.Read())
{
Console.WriteLine(xml.Name);
}
}
}
我有另一个HttpWebRequest 的代理代码:
if(Convert.ToBoolean(ConfigurationManager.AppSettings["behindproxy"]) == true)
{
WebProxy proxy = new WebProxy();
Uri proxyUri = new Uri("srvisa01");
proxy.Address = proxyUri;
proxy.BypassProxyOnLocal = true;
proxy.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["proxyusername"].ToString(), ConfigurationManager.AppSettings["proxypassword"].ToString());
}
但我不确定这在这种情况下是否有效。
帮助表示赞赏。
亲切的问候
克里斯
【问题讨论】:
-
您是否需要特定的凭据,或者您的 app.config 中的 adding proxy configuration 是否足够?
-
不幸的是,具体的凭据,这让事情变得棘手。我确实找到了这个网站:msdn.microsoft.com/en-us/library/aa720674.aspx#Y103,但我无法让代码工作......