chrome 来自服务器的响应包含重复标头。此问题通常是由于网站或代理配置不正确导致的。只有网站或代理管理员才能解决此问题...

1 篇文章 0 订阅

今天项目中用到了写入流下载。代码如下。

 

 

HttpServletResponse reponse = super.getResponse();

reponse.setHeader("Content-Disposition", "attachment;filename=" + fileName);

reponse.setContentType("application/octet-stream");

reponse.setBufferSize(2048);

reponse.setContentLength(byteArr.length);

ServletOutputStream out = null;

try {

out = reponse.getOutputStream();

out.write(byteArr, 0, byteArr.length);

} catch (IOException e1) {

// TODO Auto-generated catch block

log.error(e1);

}

 

这段代码在项目中一直运行良好。。近日,有位兄弟,在这里面加入了点点代码。。

导致在 chorme 浏览器中,抛出异常。

 

异常如下

 

收到了来自服务器的重复标头
来自服务器的响应包含重复标头。此问题通常是由于网站或代理配置不正确导致的。只有网站或代理管理员才能解决此问题。
错误 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION):我们收到了多个“Content-Disposition”标头。我们不允许此行为,以防遭到 HTTP 响应拆分攻击。

 

 

但使用其他IE8,IE9,firefox 都运行良好。。

 

于上上网一搜,,还真搜出一堆。。解决方法如下

 

原因是因为下载文件名中包含有逗号分隔符。。在所有的浏览器中,下载文件名不支持双字节字符。

 

参考请见 http://greenbytes.de/tech/tc2231/#attmultinstances

 

 

 

Content-Disposition: attachment; filename=foo,bar.html
                                             ^ (PARSE ERROR)
Test Results
FF11warn (accepts the unquoted value)
FF14warn (accepts the unquoted value)
MSIE8warn (accepts the unquoted value)
MSIE9warn (accepts the unquoted value)
Operawarn (accepts the unquoted value)
Safariwarn (treats the comma as delimiter and offers to download "foo.html")
Konqpass (ignores thes header field)
Chr17pass (reports a network error ("Duplicate headers received from server"))
Chr18pass (reports a network error ("Duplicate headers received from server"))

'attachment', specifying a filename of foo,bar.html using a comma despite using token syntax.

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值