防止 Tomcat 将字符集附加到二进制内容类型 [英] Preventing Tomcat from appending charset to binary content types
问题描述
我们有一个基于 Restlet 的服务,它返回以下响应:
We have a Restlet based service that returns the following response:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1, Restlet-Framework/2.0.7
X-Powered-By: Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0
Content-Disposition: inline; filename=Time_for_a_breather.pdf
Date: Fri, 13 May 2011 23:41:24 GMT
Accept-Ranges: bytes
Content-Type: application/pdf;charset=UTF-8
Content-Length: 218495
但不幸的是,在某些浏览器(尤其是 Chrome)中,我们在查看 pdf 时遇到问题.
but unfortunately within some browsers (Chrome in particular) we are having problems viewing the pdf.
从实验和研究来看,问题似乎与 jBoss/Tomcat 将 charset=UTF-8 附加到内容类型有关,这导致浏览器感觉到它接收的文本数据不是二进制数据.
From experimenation and research it appears the problem is related to jBoss/Tomcat appending charset=UTF-8 to the Content Type which causes the browser to sense that its receiving text data not binary data.
有没有人知道防止 jBoss/Tomcat 将字符集附加到二进制数据的内容类型的方法?
Does anybody know of a way from preventing jBoss/Tomcat appending the charset to the content type for binary data?
推荐答案
就我而言,结果是 Spring 的 CharacterEncodingFilter
.如果您将 forceEncoding
设置为 true
,它会将字符编码添加到内容类型中,即使它对于二进制数据没有意义.
In my case, it turned out to be Spring's CharacterEncodingFilter
. If you set forceEncoding
to true
, it will add the character encoding to the content type, even if it makes no sense as for binary data.
为了修复它,请将 forceEncoding
设置为 false
或保留默认设置.并验证它的效果,例如JSON 响应.
In order to fix it, set the forceEncoding
to false
or leave it in the default setting. And verify the effect it has, e.g. on JSON responses.
这篇关于防止 Tomcat 将字符集附加到二进制内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!