[英]Unable to view 'Content-Disposition' headers in Angular4 GET response
[英]Not able to get the `Content-Disposition` from backend response
我正在嘗試從后端響應中從Content-Disposition
獲取值。 但我根本無法理解。
這是我的代碼:
public getQuoteImage(sharedQuote):Observable<any> {
return this.http.post(environment.downloadSummarUrl, JSON.stringify(sharedQuote), {
headers: this.params.headers.validate,
observe: "response",
responseType : 'blob'
});
}
我正在嘗試從以下Content-Disposition
從Content-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
});
}
但根本無法獲得價值。
在控制台中,我得到:
{
"headers": {
"normalizedNames": {
},
"lazyUpdate": null,
"lazyInit": null,
"headers": {
}
},
"status": 200,
"statusText": "OK",
"url": "https:XXXXXXservice/p/shipment/download/",
"ok": true,
"type": 4,
"body": {
}
}
根據MDN Access-Control-Expose-Headers文檔 ,CORS請求僅允許javascript訪問以下響應頭:
服務器可以使用Access-Control-Expose-Headers
響應允許訪問其他響應頭,因此,要讓客戶端可以訪問Content-Disposition
,您需要發出
Access-Control-Expose-Headers: Content-Disposition
響應中的標題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.