【问题标题】:Download rss as xml (by default it returns html)将 rss 下载为 xml(默认返回 html)
【发布时间】:2014-07-08 23:34:49
【问题描述】:

这是链接 https://www.facebook.com/feeds/page.php?format=rss20&id=126895537502383

问题是当我通过 WebClient DownloadString() / DownloadData() 方法下载它时,它给了我 html 代码

注意:似乎来源取决于我将打开链接的浏览器,在 google chrome 上我看到了一个不错的 xml 代码,但在 Firefox 中我看到这些东西是用 HTML 修饰的

那么...我如何下载此链接的原生 xml 代码?

【问题讨论】:

    标签: c# xml string download rss


    【解决方案1】:

    只需设置User-Agent 标头

    var wc = new Webclient();
    wc.Headers["User-Agent"] = "Stackoverflow/0.0";
    var xml = wc.DownloadString("https://www.facebook.com/feeds/page.php?format=rss20&id=126895537502383");
    

    【讨论】:

      【解决方案2】:

      您可以使用 WebClient 类的 DownloadFile 方法。

      var client = new WebClient();
      client.DownloadFile("https://www.facebook.com/feeds/page.php?format=rss20&id=126895537502383", @"C:\feed.xml");
      

      【讨论】:

        猜你喜欢
        • 2020-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多