Reputation: 1185
I'm trying to make a http post in angular 2 below is the code snippet. HTTP post adds quotes " " around the json object and hence the call fails. How can I remove those quotes from my request?
export class Compentency {
competencies : number[];
}
postData() {
let array = [1, 2, 3, 6];
this.comp.competencies = array;
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
let options = new RequestOptions({ headers: headers, method: 'post' });
return this.http.post(this.postUrl, this.comp, options)
.map(res => res.json().data.competencies)
.catch(this.handleError);
}
below is the form data passed to server
{
"competencies": [ 1, 2, 3, 6 ]
}:
Upvotes: 1
Views: 1372
Reputation: 1185
I had to change the headers content type to application/json and it works now.
Upvotes: 1