'Content type 'text/plain;charset=UTF-8' not supported for post request in angular 4

I'm using post request with HttpClient like below,

return this.httpclient.post<any>(url, body)
            .catch(this.handleError)

then it gives me below error,

Content type 'text/plain;charset=UTF-8' not supported

Then I tried to add headers like below,

const headers = new HttpHeaders({'Content-Type':'application/json; charset=utf-8'});


        return this.httpclient.post<any>(url, body, {headers: headers})
            .catch(this.handleError)

then it gives me below error,

Response for preflight has invalid HTTP status code 403

  • this works fine with get request.

what is the reason for this. hope your help with this



Solution 1:[1]

Try somethink like this :

 let body = {dataToSend};
         this.httpClient.post(url, body)
        .subscribe(function(data) {
                console.log(data);
        });

It works for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Léo R.