Refused to get unsafe header "Content-Disposition"
XMLHttpRequest / ajax / axios not take header won the way.
//获取heade方法
//XMLHttpRequest
XMLHttpRequest.getResponseHeader("Content-Disposition");
XMLHttpRequest.getAllResponseHeaders();
//ajax ???
response.headers("Content-Disposition")
Solution:
//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");
references:
angularjs file downloads and get the file name from the response header in
How to solve cross-domain in the Refused to get unsafe header "date"