I am passing responseType: 'blob' via get request. It works well.
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { RequestOptions, Response, ResponseContentType } from '@angular/http';
let headers = new HttpHeaders();
headers = headers.set('Content-Type', 'application/pdf');
return this.http.get(url, {
headers: headers,
responseType: 'blob'
}
How to pass same responseType via post request?
I tried :
const headers = new Headers({
'Content-Type': 'application/pdf'
});
const options = new RequestOptions({headers: headers});
options.responseType = ResponseContentType.Blob;
return this.http.post(url, body, options)
but it doesnt work. I have error message: Argument of type '{ headers: Headers; }' is not assignable to parameter of type 'RequestOptionsArgs'. Types of property 'headers' are incompatible. Type 'Headers' is not assignable to type 'Headers'.
UPD Following comments bellow i've remade request:
const headers = new HttpHeaders({ 'Content-Type': 'application/pdf'});
return this.http.post(url, body, { headers, responseType:'blob' })
It works well! Thanks a lot!
Use
responseType:'blob' as 'json'
References:
You need to use is as json,
responseType:'blob' as 'json'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With