通过Axios访问响应头 [英] accessing response header via Axios
问题描述
我正在使用Axios对API进行安全的POST调用. 这会在位置"下的响应标头中返回一个URL.
I'm using Axios to make a secure POST call to an API. This returns an URL within the response headers under 'Location'.
我可以看到该URL正在Chrome的开发工具中填充:
I can see the URL being populated within Chrome's dev tools:
但是来自Axios的JS内部响应(如下)不包含此信息:
but the response inside JS from Axios (below) doesn't contain this information:
任何建议都收到了!
推荐答案
可能是因为您执行的是cors请求,默认情况下不公开位置标头.
Possibly it occurs because you are doing a cors request that doesn't expose location header by default.
您需要将此Cors配置添加到服务器端应用程序.
You need to add this Cors Configuration to your server side app.
访问控制公开标题:位置
Access-Control-Expose-Headers: Location
,您可以在这里看到: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
as you can see here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
这篇关于通过Axios访问响应头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!