http – API return code 200 with a response but can't get the response data Angular – Stack Overflow
The default http request expects a json object as a response from your API. If your API responds with a string or a plain text like “Ok”, then while subscribing it throws an error even though the status code was 200. Because it was expecting a json object, but instead it received a plain text or string.
To counter that you need to set the responseType header to “text” before sending your request. Something like this:
const options = {
headers: new HttpHeaders({
'Accept': 'text/html, application/xhtml+xml, */*',
'Content-Type': 'application/json; charset=utf-8'
}),
responseType: 'text' as 'text'
};
this.http.post(url, body, options)
Read more here: Source link