我用于即时压缩的 webapi 方法使用此代码
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new PushStreamContent((stream, content, arg3) =>
{
using (var zipEntry = new Ionic.Zip.ZipFile())
{
using (var ms = new MemoryStream())
{
_xmlRepository.GetInitialDataInXml(employee, ms);
zipEntry.AddEntry("content.xml", ms);
zipEntry.Save(stream); //process sleep on this line
}
}
})
};
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "FromPC.zip"
};
result.Content.Headers.ContentType =
new MediaTypeHeaderValue("application/octet-stream");
return result;
我想要
1) 从 _xmlRepository.GetInitialDataInXml 获取数据
2) 通过 Ionic.Zip 即时压缩数据
3) 返回压缩流作为我的 WebApi 操作的输出
但是在这一行 zipEntry.Save(stream); 执行过程停止并且不转到下一行。并且方法不返回任何东西
那么为什么它不返回我的文件?