When trying to load an xlsx file from an API, I encountered an error because Angular automatically tries to parse the body as JSON.
To resolve this issue, I found that specifying the response type directly in the request works:
this.http.get(this.url + "/getExcel", {responseType:'blob'});
However, when I also need to include authorization in the headers, it doesn't work as expected:
const headers = new HttpHeaders({
responseType:'blob',
'Content-Type': 'application/json',
'Authorization': this.authService.getToken()
})
this.http.get(this.url + "/getExcel",{headers});
I'm puzzled as both approaches should achieve the same outcome. What could be causing the difference?