您好,我正在学习这些东西,我需要向站点发送请求以获取 xml 作为响应,而不是对其进行反序列化并查看其中的任何内容...我创建了请求反序列化方法和流方法以及 Xml Schema,但现在我不知道接下来会发生什么不工作,所以如果有人知道一些不错的教程,请给我链接。
public static class LoadXml
{
public static root material;
public static void LoadXML()
{
var serviceUrl = "http://api.deezer.com/2.0/artist/27&output=xml";
string serviceName = "Deezer";
HttpWebRequest request = null;
WebResponse response = null;
request = WebRequest.Create(serviceUrl) as HttpWebRequest;
request.Method = "GET";
request.ContentType = " text/xml";
material = Deserialize<root>(GetResponseStream(request, response, serviceName));
Console.WriteLine(material.ToString());
}
public static T Deserialize<T>(MemoryStream stream)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
T result = (T)serializer.Deserialize(stream);
return result;
}
public static MemoryStream GetResponseStream(HttpWebRequest request, WebResponse response, string debugServiceName)
{
response = request.GetResponse();
MemoryStream stream = new MemoryStream();
response.GetResponseStream().CopyTo(stream);
stream.Position = 0;
return stream;
}
}