Here's my code:
const dummydata = {
param1: 72766,
param2: 'ELS'
}
var foo = JSON.stringify(dummydata)
let headers = new Headers();
headers.append('content-type', 'application/json');
this.http.post(url, foo, { headers: headers }).map(res => res.json()).subscribe(
() => { alert('Success'); }
);
For some reason there's no data going to the server as form-data
in Request Payload
and the type is getting converted to OPTIONS
instead of POST
On the other hand if I remove, headers
, then the form-data
is going but another error occurs:
415 Unsupported Media Type
UPDATE: JQuery Ajax is working
UPDATE2: Already tried this:
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });