I have a Java based API set up on a server. URL = "ex.com"
It has an endpoint which returns a PDF file. URL = "ex.com/pdf"
It expects a POST request with a parameter specifying which PDF is being requested. params = { location: "report.pdf"}
I would like to be able to use the Angular Http.post observable to get the PDF but it keeps throwing an HttpErrorResponse Http failure during parsing for http://ex.com/pdf
... Unexpected token % in JSON at position 0 at JSON.parse
. But its a PDF I dont want it to be parsed as JSON.
This is my code:
params = {location: "report.pdf"};
return this.http.post<Response>("http://ex.com/pdf", params)
.subscribe(
data => {
var file = new Blob([data], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
}
);
The endpoint works with PostMan. I can use the "Send and Download" option to successfully get the PDF file. So I just need to figure out how to do with in Angular. Appreciate the help.