javascript 尝试在 Chrome 中打开 PDF 时出现“错误 321:ERR_INVALID_CHUNKED_ENCODING”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13404200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:39:57  来源:igfitidea点击:

Getting "Error 321:ERR_INVALID_CHUNKED_ENCODING" when trying to open PDF in Chrome

javascripthtmlrestjakarta-ee

提问by Chandu

I has written the REST web service to download the PDF file from the server and sends the response as content-type=application/pdf to the browser.Below is the REST service url ,which we are calling to download PDF file from the server is throwing "Error 321:ERR_INVALID_CHUNKED_ENCODING" when opening the PDF file in the browser

我已经编写了 REST web 服务来从服务器下载 PDF 文件,并将响应作为 content-type=application/pdf 发送到浏览器。下面是 REST 服务 url,我们调用它从服务器下载 PDF 文件是在浏览器中打开 PDF 文件时抛出“错误 321:ERR_INVALID_CHUNKED_ENCODING”

Window.open("https://www.somedomain.com/appservice/resource/pdf")

The same web service, if we are calling with out using SSL(using http) and using ip ,port ,is working good.Below is the REST service Url,which displays the PDF file correctely.

相同的 Web 服务,如果我们在不使用 SSL(使用 http)和使用 ip ,port 的情况下调用,则运行良好。下面是 REST 服务 Url,它正确显示 PDF 文件。

Window.open("http://ip:port/appservice/resource/pdf")

For downloading the images from server ,Both the services (Http and Https) are working good,Only with the PDF files , I am getting this issue...

为了从服务器下载图像,服务(Http 和 Https)都运行良好,只有 PDF 文件,我遇到了这个问题...

Is this issue is because of SSL configuration ? If so how it is working for Image? Please let me know ,how to fix this..

这个问题是因为 SSL 配置吗?如果是这样,它如何为 Image 工作?请让我知道,如何解决这个问题..

回答by Chandu

My problem got solved by adding the Content-Length to the response header , the length of the file in bytes.

我的问题通过将 Content-Length 添加到响应头(文件的长度(以字节为单位))来解决。

response.setHeader("Content-Length", "");

回答by Matt Brock

It could be a cache-control issue. If you can control the headers that are sent back to the client (which I'm guessing you can if you're building & streaming back a PDF), try adding these to the https response and see what happens:

这可能是缓存控制问题。如果您可以控制发送回客户端的标头(如果您正在构建和流回 PDF,我猜您可以控制),请尝试将这些添加到 https 响应中,看看会发生什么:

response.setHeader("Cache-control", "");
response.setHeader("Pragma", "");