3

我正在尝试使用以下代码从 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?谢谢

4

1 回答 1

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
于 2012-12-02T22:43:01.653 回答