我试图在变量中GZip内容输出到浏览器.首先,我正在使这个非常简单,而不是担心不支持gzip的浏览器.此外,我通过研究我可以在网上找到的几种方法将它放在一起.其中一些人可能正在阅读这个问题.
<cfsavecontent variable="toGZIP"><html><head><title>Test</title></head><body><h1>Fear my test</h1></body></html></cfsavecontent> <cfscript> ioOutput = CreateObject("java","java.io.ByteArrayOutputStream"); gzOutput = CreateObject("java","java.util.zip.GZIPOutputStream"); ioOutput.init(); gzOutput.init(ioOutput); gzOutput.write(toGZIP.getBytes("UTF-8"),Len(toGZIP.getBytes())); gzOutput.finish(); gzOutput.close(); ioOutput.flush(); ioOutput.close(); toOutput=ioOutput.toString("UTF-8"); </cfscript> <cfcontent reset="yes" /><cfheader name="Content-Encoding" value="gzip"><cfheader name="Content-Length" value="#ArrayLen( toOuptut.getBytes() )#" ><cfoutput>#toOuptut#</cfoutput><cfabort />
但我在Firefox(以及Chrome和Safari)中出错
Content Encoding Error
The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.
有人有什么想法吗?
操作系统:Mac OX-X Snow Leopard
CF:9-Dev
网络服务器:Apache
解
<cfsavecontent variable="toGZIP"><html><head><title>Test</title></head><body><h1>Fear my test</h1></body></html></cfsavecontent> <cfscript> ioOutput = CreateObject("java","java.util.zip.GZIPOutputStream"); ioOutput.init(); gzOutput.init(ioOutput); gzOutput.write(toGZIP.getBytes(),Len(toGZIP.getBytes())); gzOutput.finish(); gzOutput.close(); ioOutput.flush(); ioOutput.close(); toOutput=ioOutput.toByteArray(); </cfscript> <cfheader name="Content-Encoding" value="gzip"><cfheader name="Content-Length" value="#ArrayLen(toOutput)#" ><cfcontent reset="yes" variable="#toOutput#" /><cfabort />