我有一个下载文件的 web api 方法:
public HttpResponseMessage DownloadDocument()
{
XDocument xDoc = GetXMLDocument();
MemoryStream ms = new MemoryStream();
xDoc.Save(ms);
ms.Position = 0;
var response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StreamContent(ms),
};
// Sending metadata
// Is this the right way of sending metadata about the downloaded document?
response.Content.Headers.Add("DocumentName", "statistics.xml");
response.Content.Headers.Add("Publisher", "Bill John");
return response;
}
这是发送有关我返回的 StreamContent 元数据的正确方法吗?还是我应该返回不同类型的内容?