我编写了一个 Web API 代码来返回一个 zip 文件。但我无法将 GZipStream 内容转换为 HttpContent。我收到以下错误:
无法将类型“system.io.compression.GZipStream”隐式转换为“System.Net.Http.HttpContent”
我哪里做错了?
我的 WebApi 代码:
var content =
new GZipStream(memStream, CompressionMode.Compress);
HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
httpResponseMessage.Content = content;
httpResponseMessage.Content.Headers.Add("x-filename", document.FileName);
httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
httpResponseMessage.Content.Headers.ContentDisposition.FileName = "xyz.zip";
httpResponseMessage.StatusCode = HttpStatusCode.OK;
隔江千里
九州编程
相关分类