Search code examples
angularhttpclient

Can't change Content-Type in http post request using angular


I can't change Content-Type to application/json in headers of post request. I use angular 6. Request is rejected with error (Unsupported Media Type) Same request working with old http from '@angular/http'.

I use visual studio debug for running application. Web api is .net core.

import { HttpClient, HttpRequest, HttpEventType, HttpResponse, HttpHeaders 
} from '@angular/common/http';

var body = JSON.stringify(model);
let headers = new HttpHeaders();
headers = headers.set('Content-Type', 'application/json');

let httpOptions = {headers: headers,};

this.http.post(this.Url, body, httpOptions).subscribe(x => { })

Request result


Solution

  • Solution: I used HttpInterceptor which replace request headers