【问题标题】:c# Unable to parse xml, receiving error 463c#无法解析xml,收到错误463
【发布时间】:2016-03-26 17:26:06
【问题描述】:

基本上我正在尝试解析xml from this
但是我收到{“远程服务器返回错误:(463)。”}(System.Net.WebException)错误发生在string xml = webClient2.DownloadString(address);

这是我的完整代码

Task.Run((Action)(() =>
        {
            XmlDocument xmlDocument = new XmlDocument();
            using (WebClient webClient1 = new WebClient())
            {
                WebClient webClient2 = webClient1;
                Uri address = new Uri("https://habbo.com/gamedata/furnidata_xml/1");
                string xml = webClient2.DownloadString(address);
                xmlDocument.LoadXml(xml);
            }
            foreach (XmlNode xmlNode1 in xmlDocument.GetElementsByTagName("furnitype"))
            {
                string nr1 = "[" + xmlNode1.Attributes["id"].Value + "]";
                string nr2 = " : " + xmlNode1.Attributes["classname"].InnerText;
                foreach (XmlNode xmlNode2 in xmlNode1)
                {
                    XmlNode childNode = xmlNode2;
                    if (childNode.Name == "name")
                    {
                        this.FurniCB.Invoke((Action)(() => this.FurniCB.Items.Add((object)(nr1 + nr2 + " : " + childNode.InnerText))));
                        this.FurniDataList.Add(nr1 + nr2 + " : " + childNode.InnerText);
                    }
                }
            }
        }));

提前致谢

【问题讨论】:

    标签: c# xml parsing task


    【解决方案1】:

    我测试了您的代码的下载部分。您只需将User-Agent 标头添加到请求中即可。

    webClient1.Headers.Add("User-Agent", "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 2019-12-26
    • 1970-01-01
    • 2013-10-17
    • 1970-01-01
    相关资源
    最近更新 更多