我正在尝试使用以下代码从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? 感谢
答案 0 :(得分:1)
这应该有效:
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