我正在尝试使用新的 HttpClient 从我的后端获取一个文件(数组缓冲区)。
我的代码很像下面这样:
this.http.post(url, body, {responseType: 'blob', observe: 'response'})
.subscribe(resp => {
console.log(resp.headers.get('content-disposition'));
});
我浏览器控制台的响应是null
当我查看网络选项卡时,我看到内容配置的值类似于 附件; filename="whatever"
如果我尝试获取 content-type,那么我会收到一些东西。
你有没有经历过类似的事情,或者你能告诉我我还必须做什么吗? 非常感谢
最佳答案
我遇到了同样的问题并找到了这个 https://stackoverflow.com/a/45482346/1909698
在我的后端响应 header 中添加 'Access-Control-Expose-Headers': 'Content-Disposition'
后它对我有用。
关于Angular 4 新的 HttpClient 内容配置 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47160234/