我正在使用此代码从 URl 获取 XML 数据:
using (WebClient wc = new WebClient())
{
wc.Credentials = new NetworkCredential("admin", "admin");
string xml = wc.DownloadString("http://somedomain.com:8550/epe/postaglist");
XmlDocument tournamentsXML = new XmlDocument();
tournamentsXML.LoadXml(xml);
XmlNodeList TagList = tournamentsXML.GetElementsByTagName("TAG");
foreach (XmlNode node in TagList)
{
XmlElement TagElement = (XmlElement)node;
string TagID = TagElement.GetElementsByTagName("tagid")[0].InnerText;
string MAC = TagElement.GetElementsByTagName("mac")[0].InnerText;
Messagbox.Show(TagID+","+MAC));
}
}
它工作正常 100%。但是当更改链接以添加这样的查询字符串时:
“ http://somedomain.com:8550/epe/pos/taglist?fields=posgood ”
它给了我身份验证异常 401 请注意它在 IE 或 firefox 浏览器上工作正常!
我很累,因为从昨天开始仍在尝试解决这个异常,但我不能:(