I'm currently in the process of getting my feet wet in Angular and experimenting with http.post reponses. I am able to get the response as json without any trouble, however having trouble getting the response as plain text.
This is what I am trying so far to get the response as text:
this.http.post<string>(`http://server/test.php`,
{ title: 'Angular POST Request Example' }).subscribe(data => {
console.log(data);
});
test.php simply returns a string such as "hello world"
The browser throws an error object in which I can see the following:
"Unexpected token h in JSON at position 0"
Therefore it looks like it's trying to parse it as json.
How can I force it simply text as the result and not parse as Json?
I've has a look at other solutions which suggest adding headers or even setting "responseType: 'text' as 'json'" in the options (the latter works for me), but I get the impression that the type in the function should cause the function to expect text data as the response.
Kind Regards Musaffar