无法访问 axios 中的 Content-Disposition

Ask*_*ing 13 javascript response-headers reactjs axios

我有一个 React JS 应用程序,我在其中使用 axios 发送 GET 请求。在浏览器的Response Headers部分中,当我发送请求时,我得到了Content-Disposition: attachment;filename="image123.pdf",但是当我尝试在 React 中获取它时,我没有得到任何具有该名称的字段。因此,当我尝试访问 时response.headers['content-disposition'],我什么也得不到。

是否可以使用 React JS 使用 axios 读取此标头键?

Ami*_*ami 1

您必须确保服务器端已通过 CORS 授予了适当的访问权限。您可以通过以下代码进行快速对比,以确保服务器端访问该特定事务没有问题。在服务器中检查:

res.header('Access-Control-Expose-Headers', 'Content-Disposition');
Run Code Online (Sandbox Code Playgroud)

您的下一步是确保将这两项从客户端发送到服务器。

在标头中设置(客户端):

responseType: 'blob',
withCredentials: true,
Run Code Online (Sandbox Code Playgroud)