Refused to get unsafe header "Content-Disposition

Refused to get unsafe header "Content-Disposition"

XMLHttpRequest/ajax/ axios中获不到取header办法。

//获取heade方法

//XMLHttpRequest
XMLHttpRequest.getResponseHeader("Content-Disposition");
XMLHttpRequest.getAllResponseHeaders();
//ajax ???
response.headers("Content-Disposition")

解决办法:

//nodejs-expressjs为例
 res.writeHead(200, {
      "Access-Control-Allow-Origin": '*',
      'Content-Type': 'application/octet-stream;charset=UTF-8',
      "Access-Control-Expose-Headers":'Content-Disposition',//如果不暴露header,那就Refused to get unsafe header "Content-Disposition"
      "Content-Disposition":  'attachment;filename='+ filename,
    });//设置响应头


//java ???
context.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");

参考文献:

angularjs 文件下载 并 从response header中获取文件名

如何解决跨域中的Refused to get unsafe header "date"

从XMLHttpRequest请求响应里getResponseHeader(header)报错:Refused to get unsafe header "**" 问题解决

Refused to get unsafe header “Content-Range”

posted @ 2020-02-25 15:43  marvelousone  阅读(16507)  评论(0编辑  收藏  举报