我正在尝试使用以下代码从URL获取XML数据:
WebRequest webRequest = WebRequest.Create(Url);
using (WebResponse webResponse = await webRequest.GetResponseAsync())
{
using (Stream responseStream = webResponse.GetResponseStream())
{
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load(webResponse); ////error
}
}
Visual Studio 不接受 "XMLDoc.Load()" 和 "XMLDoc.LoadXml()" - 那么,如何从 webrequest 获取 xmldoc?谢谢
这应该有效:
string url = @"http://ws.audioscrobbler.com/2.0/?method=geo.getevents&location=" + ub.Ciudad + "&page=1&api_key=" + LAST_API_KEY; //for example
XmlDocument xDoc = await XmlDocument.LoadFromUriAsync(new Uri(url)); //this does the web request