简体   繁体   English

无法从后端响应获取“ Content-Disposition”

[英]Not able to get the `Content-Disposition` from backend response

I am trying to get the value from Content-Disposition from my backend response. 我正在尝试从后端响应中从Content-Disposition获取值。 but I am not able to get that at all.. 但我根本无法理解。

here is my code : 这是我的代码:

public getQuoteImage(sharedQuote):Observable<any> {
    return this.http.post(environment.downloadSummarUrl, JSON.stringify(sharedQuote), { 
      headers: this.params.headers.validate,
      observe: "response",
      responseType : 'blob'
    });
  }

I am trying to get filename from Content-Disposition from the following: 我正在尝试从以下Content-DispositionContent-Disposition获取filename

downloadSummaryContent() {
    this.server.getQuoteImage(this.sharedQuote).subscribe((data) => {
      console.log( 'headers are', '\n', data, '\n',  data.headers.get('Content-Disposition') ); //but not getting the file name
      var url = window.URL.createObjectURL(data);
      var a = document.createElement('a');
      document.body.appendChild(a);
      a.setAttribute('style', 'display: none');
      a.href = url;
      a.download = 'quote.pdf';
      a.click();
      window.URL.revokeObjectURL(url);
      a.remove(); // remove the element
    });
  }

在此处输入图片说明

But not getting the value at all. 但根本无法获得价值。

in the console i am getting: 在控制台中,我得到:

{
  "headers": {
    "normalizedNames": {

    },
    "lazyUpdate": null,
    "lazyInit": null,
    "headers": {

    }
  },
  "status": 200,
  "statusText": "OK",
  "url": "https:XXXXXXservice/p/shipment/download/",
  "ok": true,
  "type": 4,
  "body": {

  }
}

According to MDN Access-Control-Expose-Headers documentation , CORS requests only allows javascript to access the following response headers: 根据MDN Access-Control-Expose-Headers文档 ,CORS请求仅允许javascript访问以下响应头:

  • Cache-Control 缓存控制
  • Content-Language 内容语言
  • Content-Type 内容类型
  • Expires 过期
  • Last-Modified 上一次更改
  • Pragma 语用

The server can allow access to other response headers using the Access-Control-Expose-Headers response, so, for Content-Disposition to be accessible to the client, you would need to issue 服务器可以使用Access-Control-Expose-Headers响应允许访问其他响应头,因此,要让客户端可以访问Content-Disposition ,您需要发出

Access-Control-Expose-Headers: Content-Disposition

header in the response 响应中的标题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在Angular4 GET响应中查看“Content-Disposition”标头 - Unable to view 'Content-Disposition' headers in Angular4 GET response 如何从内容处置中获取文件名 - How to get file name from content-disposition 从 ASP.NET CORE Web Api 获取 React 中的特定响应标头(例如,Content-Disposition) - Get a specific response header (e.g., Content-Disposition) in React from an ASP.NET CORE Web Api XMLHttpRequest 是否阻止了 Content-Disposition 附件? - Is Content-Disposition attachment blocked from XMLHttpRequest? 从 Rest API 响应内容处置输出 [Object, Object] 下载 javascript 中的 excel 文件 - Download excel file in javascript from Rest API response content-disposition outputs [Object, Object] HTTP 带有 Content-Disposition 的响应不会触发下载 - HTTP Response with Content-Disposition doesn't trigger download 使用symfony2从邮件Multipart(Content-Disposition:form-data)获取数据 - Get Datas from post Multipart (Content-Disposition: form-data) with symfony2 内容处置始终为 null - Content-Disposition is always null 用于从 Content-Disposition 标头中提取文件名的 javascript 正则表达式 - javascript regex for extracting filename from Content-Disposition header 从帖子中使用用户脚本更改Content-Disposition文件名 - Change Content-Disposition filename with userscript from a Post
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM