Angular 角体未按post请求正确通过
我有一个简单的post api,它在postman中运行良好,当我试图通过它不传递的方式发送它时 我是这样做的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
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)