gpt4 book ai didi

asp.net-mvc - 资源被解释为文档,但使用 MIME 类型应用程序/zip : 传输

转载 作者:行者123 更新时间:2023-12-03 23:50:51 24 4
gpt4 key购买 nike

我无法使用 Web API get 调用从服务器成功下载文件。下载似乎开始了,但随后 Chrome 抛出:

“资源被解释为文档,但使用 MIME 类型应用程序/zip 传输”

Firefox 没有说,但下载仍然失败。

我在以下设置中做错了什么?:

    [HttpGet, Route("api/extractor/downloadresults")]
public HttpResponseMessage DownloadResultFiles()
{
int contentLength = 0;
this.ResultFiles.ForEach(f => contentLength = contentLength + f.FileSize);

var streamContent = new PushStreamContent((outputStream, httpContext, transportContent) =>
{
...zip files...
});

streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
streamContent.Headers.ContentLength = contentLength;
streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "result.zip"
};

var response = Request.CreateResponse();

response.StatusCode = HttpStatusCode.OK;
response.Content = streamContent;
}

我通过以下方式触发下载:
  window.location.href = "api/extractor/downloadresults";

使用结果标题:

请求头
  Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:ASP.NET_SessionId=ibwezezeutmu2gpajfnpf41p
Host:localhost:47384
Referer:http://localhost:47384/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36

响应头
  Cache-Control:no-cache
Content-Disposition:attachment; filename=result.zip
Content-Length:436102
Content-Type:application/zip
Date:Mon, 16 Dec 2013 22:36:31 GMT
Expires:-1
Persistent-Auth:true
Pragma:no-cache
Server:Microsoft-IIS/8.0
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?QzpcbmV3VG9vbGJveFxUb29sYm94XFRvb2xib3guV2ViXGFwaVx0ZXJtZXh0cmFjdG9yXGRvd25sb2FkcmVzdWx0ZmlsZXM=?=

最佳答案

您是否尝试过更改请求 header ,例如接受 header ?

另外,here您可以找到类似的问题,那里建议的一些解决方案可能对您有所帮助。

关于asp.net-mvc - 资源被解释为文档,但使用 MIME 类型应用程序/zip : 传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20622532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com