【问题标题】:Failed - network error in get Zip file in chrome失败 - 在 chrome 中获取 Zip 文件时出现网络错误
【发布时间】:2017-07-08 18:23:22
【问题描述】:

我正在通过Ionic.Zip.dll 像这样(ASP.NET,C#)创建一个 zip:

zip.AddEntry("Document.jpeg", File.ReadAllBytes("Path");

我想这样下载:

Response.Clear();
Response.BufferOutput = false;
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=SuppliersDocuments.zip";
zip.Save(Response.OutputStream);
Response.Close();

我通过 Firefox 和 Chrome 在 localhost 中测试了这段代码,它运行正常。但是当我在主机中测试这段代码时,我得到了这个错误:

失败 - 网络错误

我的代码错了吗?

【问题讨论】:

  • 尝试将 content-Size 添加到响应标头。让我知道它是否有效。

标签: asp.net google-chrome zip response ionic-zip


【解决方案1】:

我在转发 SSRS 报告时遇到了类似的问题。接受@Arvin 的建议,我做了以下事情:

private void CreateReport(string ReportFormat)
{
    ReportViewer rview = new ReportViewer();

    // (setup report viewer object)

    // Run report
    byte[] bytes = rview.ServerReport.Render(ReportFormat, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings); 

    // Manually create a response
    Response.Clear();
    Response.ContentType = mimeType;
    Response.AddHeader("Content-disposition", string.Format("attachment; filename={0}.{1}", fileName, extension));

    // Ensure the content size is set correctly
    Response.AddHeader("Content-Length", bytes.Length.ToString()); // <- important

    // Write to the response body
    Response.OutputStream.Write(bytes, 0, bytes.Length);

    // (cleanup streams)
}

修复方法是添加 Content-Length 标头并将其设置为来自报告服务的字节数组的大小。

【讨论】:

    猜你喜欢
    • 2017-07-07
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 2016-03-02
    • 1970-01-01
    • 2019-12-26
    相关资源
    最近更新 更多