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)
{
Try this code:
private _getHeaders():Headers {
let header = new Headers({
'Content-Type': 'application/json'
});
return header;
}
public login(url, postdata){
let options = new RequestOptions({
headers: this._getHeaders()
});
return this.http.post(url, JSON.stringify(postdata),options).map(res => res.json());
}