XDocument Load - cannot open

前提是你 提交于 2020-01-07 04:59:11

问题


I'm trying to load rss feed by XDocument. The url is:

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

XDocument doc = XDocument.Load(url);

But I'm getting an error:

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

回答1:


XDocument.Load does not take URL's, only files as stated in the documentation.

Try something like the following code which I totally did not test:

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());
}


来源:https://stackoverflow.com/questions/42257147/xdocument-load-cannot-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!