[英]Angular 4 new HttpClient content-disposition header
我正在嘗試使用新的 HttpClient 從我的后端獲取文件(數組緩沖區)。
我的代碼非常類似於以下內容:
this.http.post(url, body, {responseType: 'blob', observe: 'response'})
.subscribe(resp => {
console.log(resp.headers.get('content-disposition'));
});
我的瀏覽器控制台中的響應為空
當我查看 network 選項卡時,我看到 content-disposition 有一個類似於attach的值; 文件名=“隨便”
如果我嘗試獲取內容類型,那么我會收到一些東西。
你有沒有經歷過類似的事情,或者你能告訴我我還需要做什么嗎? 非常感謝
我有同樣的問題,發現這個https://stackoverflow.com/a/45482346/1909698
在我的后端響應標頭中添加'Access-Control-Expose-Headers': 'Content-Disposition'
后,它對我有用。
如果您的后端使用SpringSecurity
您需要將ExposeHeader
添加到配置源:
@Bean
protected CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.addExposedHeader("Content-Disposition");
return source;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.