为什么我的POST方法在Angular中不起作用

时间:2020-09-09 03:33:35

标签: javascript node.js angularjs http http-post

以邮递员发送数据时,我的状态为200-成功[screen form postman1

但是当我尝试通过Angular CLI将POST请求发送到相同的URL时,出现了400错误,提示MALFORMED_JSON

 const testData = {
    "address_1": "ddd",
    "contact_person_1": "ddd",
    "full_name": "dsad",
    "is_active": 2,
    "phone_no_1": "11111",
  }
return this.http.post(`${this.urlAdmin}branches/save`, testData).pipe(
  catchError((err) => {
      console.log('err' , err)
    return of(false);
  })
);

这是我在浏览器中请求的参数下面的屏幕 enter image description here

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

从Angular调用api时,可以遵循以下顺序: this.http.post(baseUrl,parameterModel,headers).pipe();

,正如我所见,您需要添加标题,模型,并确保从api路径进入。

相关问题