【问题标题】:XDocument Load - cannot openXDocument 加载 - 无法打开
【发布时间】:2017-02-15 18:17:09
【问题描述】:

我正在尝试通过 XDocument 加载 rss 提要。 网址是:

http://www.ft.com/rss/home/uk

XDocument doc = XDocument.Load(url);

但我收到一个错误:

Cannot open 'http://www.ft.com/rss/home/uk'. The Uri parameter must be a file system relative or absolute path.

【问题讨论】:

  • 错误信息很清楚:The Uri parameter must be a file system relative or absolute path 它不能是 http url bu 文件路径
  • @Cieja,我没有注意到核心标签。你是正确的 XmlTextReader 不存在。如果有一个符合核心要求的替代品就可以了。为了避免混淆,我已删除我的答案。
  • 有asp.net-core标签。

标签: c# asp.net .net asp.net-core rss


【解决方案1】:

XDocument.Load 不采用 URL,仅采用 documentation 中所述的文件。

尝试以下我完全没有测试过的代码:

using(var httpclient = new HttpClient())
{
    var response = await httpclient.GetAsync("http://www.ft.com/rss/home/uk");
    var xDoc = XDocument.Load(await response.Content.ReadAsStreamAsync());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多