gpt4 book ai didi

C# BinaryWrite 通过 SSL

转载 作者:太空狗 更新时间:2023-10-30 00:22:39 25 4
gpt4 key购买 nike

我正在尝试使用存储在 MSSQL varbinary(MAX) 字段中的 PDF 响应客户端。响应通过 http 连接在我的本地主机和测试服务器上工作,但在通过 https 连接的生产服务器上不起作用。我只使用一个简单的 BinaryWrite(下面的代码)。

    byte[] displayFile = DatabaseFiles.getPdfById(id);

Response.ContentType = "application/pdf";
Response.BinaryWrite(displayFile);

这里没什么特别的。只需获取二进制数据,设置内容类型,然后写回客户端即可。为了以这种方式通过 https 回复,是否需要做任何特别的事情?

编辑:按不起作用,我的意思是我在浏览器中得到一个空白文档。 Acrobat 无法在浏览器中加载。

编辑: 我刚刚注意到这个问题只发生在 IE 7 中。PDF 在 Firefox 3 中正确加载。我们的客户只使用 IE 7(比我说服他们升级的 IE 6 更好) ...哈哈)。

编辑:尝试添加 header “content-disposition”以使文件充当附件。浏览器无法在 SSL 下加载,并出现 IE 错误“Internet Explorer 无法从 ProductionServer.net 下载 displayFile.aspx。” (代码如下)

    byte[] displayFile = DatabaseFiles.getPdfById(id);
Response.Clear();
Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", fileName));
Response.ContentType = "application/pdf";
Response.BinaryWrite(displayFile);

编辑:如果在生产服务器上通过 http 查看文件,浏览器会显示 PDF 的代码,就像通过记事本查看一样。 (例如 %PDF-1.4 %âãÏÓ 6 0 obj <> endobj xref 6 33 ...等)

最佳答案

我只是设法通过替换来解决这个问题

Response.Clear();

Response.ClearContent();
Response.ClearHeaders();

所以整个事情看起来像:

byte[] downloadBytes = doc.GetData();
Response.ClearContent();
Response.ClearHeaders();

Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Length", downloadBytes.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=myFile.pdf");
Response.BinaryWrite(downloadBytes);
Response.Flush();
Response.End();

关于C# BinaryWrite 通过 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/356548/

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