编码
XmlTextReader reader = new XmlTextReader("http://www.meloy.kommune.no/no/Abonner-pa-nyheter/Nyheter-Meloy-Kommune/");
DataSet ds = new DataSet();
ds.ReadXml(reader);
ds.ReadXml
调用时导致此错误:
System.Net.WebException:远程服务器返回错误:(500)内部服务器错误。在 System.Net.HttpWebRequest.GetResponse() 在 System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials 凭据, IWebProxy 代理, RequestCachePolicy cachePolicy) 在 System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) 在System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) 在 System.Threading.CompressedStack.runTryCode(Object userData) 在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode 代码, CleanupCode backoutCode, Object userData) 在 System.Threading.CompressedStack。在 System.Xml.XmlTextReaderImpl 处运行(CompressedStack 压缩堆栈,ContextCallback 回调,对象状态)。
错误的原因是什么,我该如何解决?
编辑:这有效:
WebClient wc = new WebClient();
Stream st = wc.OpenRead("d:\\episerver\\test.xml");
string rss ="";
using (StreamReader sr = new StreamReader(st)) {
rss = sr.ReadToEnd();
}
XmlReader reader = XmlReader.Create(new StringReader(rss));
DataSet ds = new DataSet();
ds.ReadXml(reader);