I am trying to send HTTP post request in Angular2 but not able to set headers to content type application JSON.
My code is:
login(url,postdata)
{
Referencing the Angular 2 Angular Http Guide @angular/http has been deprecated, and @angular/common/http should be the one you are using in your Angular 2 App. Because if you do not specify http headers the default request will be sent as Content-Type text/plain, How you modify the http headers is to:
import { HttpClient, HttpHeaders } from '@angular/common/http';
.....
const req = this.http.post('/api/PostRequest/',
JSON.stringify(object),
{
headers:new HttpHeaders()
.set('Content-Type','application/json')
}).subscribe();