Manohar
Manohar

Reputation: 1185

Angular 2 http post adds quotes around json object

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

Answers (1)

Manohar
Manohar

Reputation: 1185

I had to change the headers content type to application/json and it works now.

Upvotes: 1

Related Questions