使用 Axios 获取请求的 "Content-Disposition" Header

Get "Content-Disposition" Header of a request with Axios

我正在尝试从 api 请求中获取请求的 'Content-Disposition' Header,axios 这样调用:

axios.get('Group/GetGroupObjectives', {
    params: { periodId, isPreliminary },
    responseType: 'arraybuffer',
  })
      .then((response) => {
        if (response) {
          response.request.getResponseHeader('Content-Disposition');
        } else {
          dispatch(docDownloadFailed());
        }
      })

当我收到 header 时抛出此错误 "Refused to get unsafe header "Content-Disposition"""

此问题是由 api 中的 Cors 引起的,但我在响应 header 中获得了正确获取 header 所需的所有 header:

Access-Control-Allow-Origin:*
Access-Control-Expose-Headers:*
Access-Control-Request-Headers:*
Cache-Control:no-cache
Content-Disposition:attachment; filename="sample.xlsx"
Content-Length:7965
Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Date:Fri, 26 Jan 2018 14:35:38 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/10.0
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?RDpcVGVhbV9Tb2Zhc2FcRXh0cmFuZXRcRXh

如何使用 axios 调用正确获得响应 header?

如果您使用 .NET 的 WEB API,您可以在 web.config

中设置这些 headers
   <customHeaders>
             <add name="Access-Control-Expose-Headers" value="Content-Disposition,X-Suggested-Filename"/>
      </customHeaders>

格茨