我试图获得内容处理'来自axi的api呼叫请求的标题如下:
axios.get('Group/GetGroupObjectives', {
params: { periodId, isPreliminary },
responseType: 'arraybuffer',
})
.then((response) => {
if (response) {
response.request.getResponseHeader('Content-Disposition');
} else {
dispatch(docDownloadFailed());
}
})
当我收到标题时会抛出此错误"拒绝接收不安全的标题"内容处置""
这个问题是由api中的Cors引起的,但我得到了在响应头中正确获取头所需的所有头:
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调用正确获取响应标头?
答案 0 :(得分:7)
如果您使用.NET中的WEB API,则可以在web.config中设置这些标头
<customHeaders>
<add name="Access-Control-Expose-Headers" value="Content-Disposition,X-Suggested-Filename"/>
</customHeaders>
Grtz