Refused to get unsafe header "Content-Disposition

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"

getResponseHeader (header) error in response to requests from XMLHttpRequest: Refused to get unsafe header "**" Problem Solving

Refused to get unsafe header “Content-Range”

Guess you like

Origin www.cnblogs.com/marvelousone/p/12362079.html