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.

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,我们可以得出以下结论:IIS配置响应标头中唯独不返回Access-Control-Allow-Origin。这意味着如果您正在使用IIS作为Web服务器,并且需要在Web应用程序中执行跨域Ajax请求,则需要手动将Access-Control-Allow-Origin标头添加到响应中。您可以通过以下两种方法之一来实现这一点: 1.使用IIS URL重写模块:您可以使用IIS URL重写模块来添加Access-Control-Allow-Origin标头。要执行此操作,请按照以下步骤操作: a.下载并安装IIS URL重写模块。 b.在Web.config文件中添加以下代码: ```xml <system.webServer> <rewrite> <outboundRules> <rule name="AddCrossDomainHeader"> <match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" /> <conditions> <add input="{HTTP_ORIGIN}" pattern="^https?://siteA\.com$" /> </conditions> <action type="Rewrite" value="{HTTP_ORIGIN}" /> </rule> </outboundRules> </rewrite> </system.webServer> ``` c.将“https://siteA.com”替换为您允许的域名。 2.使用ASP.NET中间件:如果您正在使用ASP.NET,则可以使用中间件来添加Access-Control-Allow-Origin标头。要执行此操作,请按照以下步骤操作: a.在Startup.cs文件中添加以下代码: ```csharp public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.Use(async (context, next) => { context.Response.Headers.Add("Access-Control-Allow-Origin", "https://siteA.com"); await next.Invoke(); }); } ``` b.将“https://siteA.com”替换为您允许的域名。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值