C# 在C中提取RSS/XML时出现问题(禁止)
我有一段代码,直到一周前一直工作正常,现在它出错了,异常显示403禁止。我一直在读到添加DefaultCredentials可能会有所帮助,但我不确定如何将其应用到我的代码中 我正在尝试从以下位置提取数据: 我的代码运行良好,它是:C# 在C中提取RSS/XML时出现问题(禁止),c#,xml,rss,linq-to-xml,C#,Xml,Rss,Linq To Xml,我有一段代码,直到一周前一直工作正常,现在它出错了,异常显示403禁止。我一直在读到添加DefaultCredentials可能会有所帮助,但我不确定如何将其应用到我的代码中 我正在尝试从以下位置提取数据: 我的代码运行良好,它是: XDocument xmlFile = XDocument.Load(@"http://na.leagueoflegends.com/en/rss.xml"); var LoLtitles = from service in xmlFile.D
XDocument xmlFile = XDocument.Load(@"http://na.leagueoflegends.com/en/rss.xml");
var LoLtitles = from service in xmlFile.Descendants("item")
select (string)service.Element("title");
var LoLlinks = from service in xmlFile.Descendants("item")
select (string)service.Element("link");
var LoLdescriptions = from service in xmlFile.Descendants("item")
select (string)service.Element("description");
var LoLDates = from service in xmlFile.Descendants("item")
select (string)service.Element("pubDate");
var servicing = LoLdescriptions.ToArray();
for (int i = 0; i < 4; i++)
{
servicing[i] = Regex.Replace(Server.HtmlDecode(servicing[i]), @"<[^>]*>", String.Empty);
}
ViewBag.titles = LoLtitles.ToArray();
ViewBag.links = LoLlinks.ToArray();
ViewBag.descriptions = servicing;
ViewBag.dates = LoLDates.ToArray();
但是现在XDocument.Load行出现了一个禁止的异常。我仍然可以手动转到.xml的url页面并查看文件/文本,因此我不确定为什么我的程序突然被拒绝访问
我已经浏览过很多地方,我正试图弄清楚如何使用人们用于URL/Web请求的方法,但是我不知道如何将其添加到XDocument或类似的方法中。有很多原因可以解释为什么我的C请求失败,而浏览器可以得到很好的问题。我想你已经看了彻底的情侣了-请考虑添加链接/细节什么不起作用。我想我的问题是如何将凭证应用到XDocument,我已经搜索了很多地方,但还没有找到可靠的答案。XDocument可以从stream/string/XmlReader加载-将它与您链接的答案结合起来,它就会工作。