Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角体未按post请求正确通过_Angular_Typescript - Fatal编程技术网

Angular 角体未按post请求正确通过

Angular 角体未按post请求正确通过,angular,typescript,Angular,Typescript,我有一个简单的post api,它在postman中运行良好,当我试图通过它不传递的方式发送它时 我是这样做的 var body : any= {"Name": this.registerForm.value.name, "ArabicName": this.registerForm.value.arname, "Description": this.registerForm.value.description, "Im

我有一个简单的post api,它在postman中运行良好,当我试图通过它不传递的方式发送它时

我是这样做的

  var body : any= {"Name": this.registerForm.value.name, "ArabicName": this.registerForm.value.arname, "Description": this.registerForm.value.description,  "Image": "sample string 5",
  "DisplayOrder": 1,
  "StatusID": 1,
  "UpdatedBy": 1};

  const headers2 = new HttpHeaders()
.set('Content-Type', 'application/json');
  console.log(body);
  this.http.post("http://itserviceapi.airtechsolutions.pk/api/admin/category/insert", {body, headers2}).subscribe((data) => {
    console.log(data);
  });
当我安慰我的身体时,它看起来像这样

  var body : any= {"Name": this.registerForm.value.name, "ArabicName": this.registerForm.value.arname, "Description": this.registerForm.value.description,  "Image": "sample string 5",
  "DisplayOrder": 1,
  "StatusID": 1,
  "UpdatedBy": 1};

  const headers2 = new HttpHeaders()
.set('Content-Type', 'application/json');
  console.log(body);
  this.http.post("http://itserviceapi.airtechsolutions.pk/api/admin/category/insert", {body, headers2}).subscribe((data) => {
    console.log(data);
  });

在邮递员身上看起来像这样

  var body : any= {"Name": this.registerForm.value.name, "ArabicName": this.registerForm.value.arname, "Description": this.registerForm.value.description,  "Image": "sample string 5",
  "DisplayOrder": 1,
  "StatusID": 1,
  "UpdatedBy": 1};

  const headers2 = new HttpHeaders()
.set('Content-Type', 'application/json');
  console.log(body);
  this.http.post("http://itserviceapi.airtechsolutions.pk/api/admin/category/insert", {body, headers2}).subscribe((data) => {
    console.log(data);
  });


我需要知道我认为需要在json或其他格式中转换的问题在哪里?

您正在将body和header作为单个参数发送到一个对象中,这可能会导致问题。Body应该作为第二个参数发送,header应该是第三个参数。像下面这样

this.http.post("http://itserviceapi.airtechsolutions.pk/api/admin/category/insert", body, { headers: headers2 })

只是
this.http.post(“http://itserviceapi.airtechsolutions.pk/api/admin/category/insert“,body)
-Angular by defect以json发送-如果要添加头,则第三个参数是:
this.http.post(”http://itserviceapi.airtechsolutions.pk/api/admin/category/insert“,车身,头部2)