I am trying to get full response from a POST request. I have read how to get full response for a get request mentioned at the official site of angular. Angular http
What it says is to add { observe: 'response' }
. But it would work for a get
request and not for post
request. post
request accepts 2-3 arguments, so I cannot send this as the 4th argument. Please have a look at my code and let me know what I am doing wrong.
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
return this.http.post('http://localhost:3000/api/Users/login', data, httpOptions, { observe: 'response' })
.do( function(resp) {
self.setSession(resp);
});
This gives me an error as 4 arguments are not allowed.
Edit
The accepted answer seems to be not working now. I am getting the following
error:
error TS2345: Argument of type '{ headers: HttpHeaders; observe: string; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
Types of property 'observe' are incompatible.
Type 'string' is not assignable to type '"body"'.
So: I needed to declare more explicitly type of httpOptions:
const httpOptions: { headers; observe; } = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
}),
observe: 'response'
};
return this.http.post('http://localhost:3000/api/Users/login', data, httpOptions) ...
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