title: How to get PDF through API in angular service
body: <p>I have a Java based API set up on a server. <code>URL = "ex.com"</code></p>
  
  <p>It has an endpoint which returns a PDF file. <code>URL = "ex.com/pdf"</code></p>
  
  <p>It expects a POST request with a parameter specifying which PDF is being requested. <code>params = { location: "report.pdf"}</code></p>
  
  <p>I would like to be able to use the Angular Http.post observable to get the PDF but it keeps throwing an HttpErrorResponse <code>Http failure during parsing for http://ex.com/pdf</code> ... <code>Unexpected token % in JSON at position 0 at JSON.parse</code>. But its a PDF I dont want it to be parsed as JSON.</p>
  
  <p>This is my code:</p>
  
  <pre><code>params = {location: "report.pdf"};
  return this.http.post&lt;Response&gt;("http://ex.com/pdf", params)
      .subscribe(
           data =&gt; {
              var file = new Blob([data], {type: 'application/pdf'});
              var fileURL = URL.createObjectURL(file);
              window.open(fileURL);
           }
       );
  </code></pre>
  
  <p>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.</p>