XPathDocument代理名称无法解析 [英] XPathDocument The proxy name could not be resolved

查看:67
本文介绍了XPathDocument代理名称无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个C#程序来从Web服务器读取XML文件.

在某些服务器上,我收到错误消息无法解析代理名称:NAME".这里有一个代理服务器,但是已被删除.错误中显示的代理服务器名称是旧的代理服务器.

如何解决这个问题.该程序作为本地系统"帐户作为服务运行.在IExplorer中未设置代理.

I wrote a C# program to read a XML file from a webserver.

On some servers I receive an error "The proxy name could not be resolved: NAME" There was a proxy server here but that is removed. The proxy servername that is displayed in the error is the old proxy server.

How to resolve this. The program runs as a service as "local System" account. In it IExplorer no proxy is setup.

XmlTextReader xmlReader = new xmlTextReader "http://www.server.eu/some.xml");
xmlReader.XmlResolver = null;
doc = new XPathDocument(xmlReader);
nav = doc.CreateNavigator();





Any ideas?

推荐答案

您需要先使用HTTPWebRequestWebClient检索xml文件,然后才能对其进行解析.
You need to retrieve the xml file with HTTPWebRequest or WebClient before you can parse it.


像这样重建它:

xtr =新的XmlTextReader(GetStreamForUri("http://www.server.eu/some.xml",路径,代理));
XPathDocument MyXMLDocument =新的XPathDocument(xtr);
导航= MyXMLDocument.CreateNavigator();

私有Stream GetStreamForUri(字符串待命,字符串路径,字符串代理)
{
WebRequest req = WebRequest.Create(bestand);
如果(proxy!=")
{
字符串uid =测试";
字符串pw =测试";
字符串贫困者= oIni.ReadValue("Proxy","Poort",");
WebProxy myProxy =新的WebProxy(
"HTTP://" +代理+:" +穷人,true);
req.Proxy = myProxy;
myProxy.Credentials =新的NetworkCredential(
uid,pw,"domain.local");
}
HttpWebResponse resp =(HttpWebResponse)req.GetResponse();
返回req.GetResponse().GetResponseStream();
}


但是仍然是相同的错误.
Rebuild it like this:

xtr = new XmlTextReader(GetStreamForUri("http://www.server.eu/some.xml", path, proxy));
XPathDocument MyXMLDocument = new XPathDocument(xtr);
nav = MyXMLDocument.CreateNavigator();

private Stream GetStreamForUri(string bestand, string path, string proxy)
{
WebRequest req = WebRequest.Create(bestand);
if (proxy != "")
{
string uid = "Test";
string pw = "Test";
string poort = oIni.ReadValue("Proxy", "Poort", "");
WebProxy myProxy = new WebProxy(
"HTTP://" + proxy + ":" + poort, true);
req.Proxy = myProxy;
myProxy.Credentials = new NetworkCredential(
uid, pw, "domain.local");
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
return req.GetResponse().GetResponseStream();
}


But still the same error.


这篇关于XPathDocument代理名称无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆