0

After trying many things read here, i still couldn't find a solution to this particular problem: I make a request from angular (localhost:4200) to an API on spring (localhost:8080), I have an HttpService that handles request just fine, until I have to make a request which response is not a JSON, but an image/png:

private httpOptions = {
headers: new HttpHeaders({
  'Accept': 'image/png',
  'Content-Type': 'image/png'
  })
};

constructor(private http: HttpService) { }

getVehicleQr(vehicleId: string): Observable<any> {
  return this.http.get('/vehicle/qr/' + vehicleId, this.httpOptions);
}

I've set the Accept and Content-Type headers in the httpOptions, yet when I execute the getVehicleQr() method, I get this error: error

this suggest that Angular is still trying to parse a JSON where i set it not to. Any suggestions? full code can be found here.

I've also seen this post.

Ariel Mirra
  • 1,117
  • 1
  • 10
  • 17
  • 1
    Probably unrelated, but still incorrect: don't set "Content-Type" - it refers to the request content (which there is none). – Julian Reschke Feb 24 '19 at 18:26
  • 1
    You posted a relevant link. Please tell us why you didn't use { responseType: 'blob' } and handle the returned blob. – rickz Feb 24 '19 at 18:31

1 Answers1

0

The problem was actually simple, as rickz pointed to, I had to add

{ responseType: 'blob' } 

in the HttpRequest Options, as is not an HttpHeader (as I originally thought) but a separate argument of the HttpRequest.

Thanks for the help!

Ariel Mirra
  • 1,117
  • 1
  • 10
  • 17