当前位置:网站首页>js无法获取headers中Content-Disposition
js无法获取headers中Content-Disposition
2022-07-25 07:09:00 【小莉爱编程】
问题重现
这里是实现了 导出的功能 但是在线上的时候 出现了 导出失败的问题;
我们需要拿到响应头里的Content-Disposition字段的值,从中分离出文件名。

本地可以看到 打印出来了content-disposition

线上的network中也可以看到 这个文件名;但是我把它从请求头中打印出来的时候,就没有这个字段;所以线上就会导出失败
分析问题
浏览器限制了这一类请求头的暴露问题;所以需要服务端配合完成;

解决方案
后端虽然加了这个;但是我们只能在network中看到,无法通过js在请求头中拿到Content-Disposition
所以还需要加一段代码
response.setHeader("Access-Control-Expose-Headers","Content-Disposition");
效果
加上这一段代码就可以导出成功了;
这里附上后端代码

边栏推荐
- Oracle table creation statement template
- Devops has been practiced for many years. What is the most painful thing?
- 杜教筛
- Basic usage of thread class
- Wechat applet wx.request interface
- New tea, start "fighting in groups"
- 【电脑讲解】NVIDIA发布GeForce RTX SUPER系列显卡,游戏玩家福利来了!
- From the era of portal to the era of information flow, good content has been ignored?
- Health clock in daily reminder tired? Then let automation help you -- hiflow, application connection automation assistant
- Kyligence Li Dong: from the data lake to the index middle stage, improve the ROI of data analysis
猜你喜欢

Software engineering in Code: regular expression ten step clearance

10分钟看懂Jmeter 是如何玩转 redis 数据库的

%d,%s,%c,%x

【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了

Labelme labels different objects, displays different colors and batch conversion

Cointegraph wrote: relying on the largest Dao usdd to become the most reliable stable currency

GIS实战应用案例100篇(十七)-基于DEM制作三维地图

微信小程序switchTab传参以及接收参数

阿里云镜像地址&网易云镜像

Restrict Su command and sudo mechanism to promote nmap and console command netstat
随机推荐
用VS Code搞Qt6:编译源代码与基本配置
Tab bar toggle style
What are the hazards of insufficient sleep?
Luo min from qudian, prefabricate "leeks"?
JS data type judgment - Case 6 delicate and elegant judgment of data type
Two week learning results of machine learning
BOM概述
【每日一题】剑指 Offer II 115. 重建序列
Upload and download multiple files using web APIs
OpenAtom XuperChain 开源双周报 |2022.7.11-2022.7.22
【SemiDrive源码分析】【驱动BringUp】39 - Touch Panel 触摸屏调试
机器学习两周学习成果
30 times performance improvement -- implementation of MyTT index library based on dolphin DB
Dart final and const variables
Wechat applet wx.request interface
Can interface debugging still play like this?
With apple not making money, the 2trillion "fruit chain" abandons "fruit" and embraces "special"
【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了
Electronic Association C language level 2 60, integer parity sort (real question in June 2021)
Devops has been practiced for many years. What is the most painful thing?