_rssSource = @"http://feeds.bbci.co.uk/news/world/rss.xml";
XmlReader reader = XmlReader.Create(_rssSource);
我有如下代码,其中在GetResponse()处抛出以下错误:
System.Net.WebException was unhandled by user code
Message=The remote server returned an error: (403) Forbidden.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri)
我已经尝试通过Fiddler跟踪请求,但除了包含代码的页面请求外,没有其他请求显示出来。该链接可以在IE / Visual Studio中正常工作。
我不确定是否与代理服务器/IIS/网络设置有关。您知道发生了什么吗?
XmlReader.Create
会引发403错误吗?实际上,网络返回了真正的403错误,但由于某种原因你无法看到它。试着用普通的WebRequest
或WebClient
获取内容,只是作为一个实验。 - John Saunders