【问题标题】:I am not able get content-disposition on client我无法在客户端获得内容配置
【发布时间】:2021-04-19 18:52:48
【问题描述】:

我正在尝试检索在后端(弹簧启动)中生成的 .xlsx 文件。在前端,我检索标题,如您所见,其中包括 content-disposition。但我无法访问标题内容配置。

正如您在下面的打印中看到的那样,标头中不存在内容处置,而是存在于 XHR 响应标头中。 Xhr 响应 console.log

我在 backed 上启用 cors 策略,

public class WebSecurityConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**");
    }
}

并在客户端获取内容配置

 public static downloadFile(data: any, untilDestroyed$: DestroyService, toasterService?: ToastrService) {
    const openInWindow = data.body.type === 'application/pdf';
    console.log(data);

    const dispositionHeader = data.headers.get('Content-Disposition'); // there is problem, value is not possible get
    const blob = new Blob([data.body], {type: data.body.type});
    const url = window.URL.createObjectURL(blob);

【问题讨论】:

    标签: angular typescript spring-boot


    【解决方案1】:

    这张票可以帮到你:Unable to view 'Content-Disposition' headers in Angular4 GET response

        CorsFilter corsFilter = new CorsFilter();
        corsFilter.setAllowedHeaders("Content-Type, Access-Control-Allow-Headers, Access-Control-Expose-Headers, Content-Disposition, 
        Authorization, X-Requested-With");
        corsFilter.setExposedHeaders("Content-Disposition");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      • 2018-08-01
      • 1970-01-01
      相关资源
      最近更新 更多