Article directory
Problem recurrence
- From the response header, there is Content-Disposition, and then the actual print:
fetch(
url,
{
method: 'GET',
headers: {
'content-type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
},
mode: 'cors',
credentials: 'include',
},
)
.then((res) => {
// 从响应头中获取 Content-Disposition
console.log('Content-Disposition :', res.headers.get("Content-Disposition")); // 打印结果为 null
})
Solution
-
The above question mentioned cannot be
content-disposition
printed out, even if the server adds this field in the protocol reply packet, but because it is not exposed to the outside, the client cannot get it. -
The response header
Access-Control-Expose-Headers
is the switch to control "exposing", which lists which headers can be exposed to the outside as part of the response. -
So if you want the client to have access to other header information, the server must not only add the header to the header, but also list them
Access-Control-Expose-Headers
in -
The backend needs to be added:
response.setHeader("Access-Control-Expose-Headers","Content-Disposition");