.net WebAPI 返回XML格式化数据(非字符串)
方式一:
HttpResponseMessage result = Request.CreateResponse<List<Student>>(HttpStatusCode.OK, list, Configuration.Formatters.XmlFormatter);
return result;
效果:
方式二:
XmlDocument doc11 = new XmlDocument();
//加载字符串
doc11.LoadXml("XML格式的字符串");
//加载文件
//xd2.Load("文件路径", "XML文件名称"));
HttpResponseMessage result1;
using (MemoryStream stream = new MemoryStream())
{
doc11.Save(stream);
result1 = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(stream.ToArray())
};
}
return result1;