我发送一个压缩文件作为响应。内容:
[HttpGet]
[Route("Package")]
public async Task<HttpResponseMessage> GetLogsPackage()
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
using (var stream = new MemoryStream())
{
using (var zipFile = ZipFile.Read((Path.Combine(path, opId.ToString()) + ".zip")))
{
zipFile.Save(stream);
response.Content = new StreamContent(stream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentLength = stream.Length;
}
}
return response;
}
调用此方法后如何获取此流?我的代码不起作用(无法读取为 zipfile) 我发送 stream.lenght,例如 345673,但收到 367 长度的响应。怎么了?
var response = await _coreEndpoint.GetLogsPackage();
using (var stream = response.Content.ReadAsStreamAsync())
using (var zipFile = ZipFile.Read(stream))
{ //do something with zip-file