简体   繁体   English

XmlDocument从URL打开

[英]XmlDocument opening from URL

I am using XmlDocument to open a remote XML document 我正在使用XmlDocument打开一个远程XML文档

string apiURL = Settings.Settings.URLBaseAPI + "user.php";

apiURL = apiURL + "?u=" + Settings.Settings.ForumUsername
       + "&p=" + MD5Tool.GetMD5Hash(Settings.Settings.ForumPassword)
       + "&mode=token";

doc.Load(apiURL);

Is there anyway to set the user agent for the internet access performed to retrieve the XML document? 无论如何,是否需要设置用户代理以执行检索XML文档的Internet访问?

When loading through the doc.Load(string) method, this is not possible. 通过doc.Load(string)方法加载时,这是不可能的。

You can try and retrieve the xml with WebClient , which will allow overriding some HTTP headers then use doc.LoadXML(string) to populate your XmlDocument. 您可以尝试使用WebClient检索xml,这将允许覆盖某些HTTP标头,然后使用doc.LoadXML(string)填充XmlDocument。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM