使用C#中的ASP.Net Core 1.0(RC2)从RSS提要中获取数据的正确/最佳方法是什么?
我想使用来自我的Wordpress博客https://blogs.msdn.microsoft.com/martinkearn/feed/的RSS feed中的数据。
我知道在ASP.net 4.x中,您会使用RssReader
或,SyndicationFeed
但是我找不到ASP.net核心的等效项。
据我所知,它返回了原始提要,但我不知道如何从中提取数据。我想列举的项目,并获得title
与description
从每一个
var feedUrl = "https://blogs.msdn.microsoft.com/martinkearn/feed/";
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(feedUrl);
var responseMessage = await client.GetAsync(feedUrl);
var responseString = await responseMessage.Content.ReadAsStringAsync();
}
根据此问题,尚未将System.ServiceModel.Syndication移植到ASP.NET Core。当前,这为您提供2个选择:
SyndicationFeed
毫无疑问,这是最简单的方法,具体取决于您的要求。
如果仅将其部署到Windows,则可以在.NET 4.X框架之上运行ASP.NET Core。为此,请project.json
使用类似的方法更新您的
frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
}
对此:
frameworks": {
"net452": {
"frameworkAssemblies": {
"System.ServiceModel": ""
}
}
}
这将为您提供最大的灵活性,因为您仍然可以使用.NET Core框架跨平台运行。将您已经获得的字符串反序列化需要更多的工作,但是有很多关于如何执行此操作的示例,例如http://www.anotherchris.net/csharp/simplified-csharp-atom-and-rss -feed解析器/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句