2016-09-29 66 views
1

我想在下面的角2中创建一个http帖子是代码片段。 HTTP post在json对象周围添加引号“”,因此调用失败。我如何从我的请求中删除这些引号?Angular 2 http post在json对象周围添加引号

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); 
    } 
下面

是传递给服务器

{ 
"competencies": [ 1, 2, 3, 6 ] 
}: 
+0

我确实为数据进行了字符串化。这仍然会在表单数据{“competencies”:[1,2,3,6]}上添加引号:我的服务器不接受密钥的引号。 – Manohar

回答

1

表单数据,我不得不内容类型更改标题为application/JSON和现在的工作。