如何在Angular中传递邮递员api数据



我尝试从Postman API手动传递json数据,它运行良好,如下所示。如何在Angular中传递Postman API的所有json数据?

组件:

logs = [{
"FPO_Name": "sample",
"FarmerCode": "sample",
"FarmerName": "sample",
"Sur_Name": "sample",
"Father_Name": "sample",
"Farmer_Dob": "1/1/1990 12:00:00 AM",
"Farmer_Address1": "sample",
"Farmer_Address2": "sample",
"Farmer_Country": "sample",
"Farmer_State": "sample",
"Farmer_District": "sample",
"Farmer_Taluk": "sample",
"Farmer_Panchayat": "sample",
"Farmer_Village": "sample",
"Farmer_Pincode": "123456",
"Gender": "Male",
"Mobile_No": "1234567890",
"RegisterDate": "01-01-2001",
"LatitudeAndLongitude": " ",
"BankAccountNo": "",
"BankName": "",
"NoOfAcres": "",
"FarmerKYC": "sample"
}];
constructor() { }
getdetails() {
return from([this.logs]);
}
sendHttpCall(firstName: string, lastName: string) {
const url = 'http://localhost:8080/yourBS/yourAPI';
const body = {
firstName, lastName // can be a JSON object
}
const headers = new Headers(
{
'Content-Type': 'application/json'
});
return this.http.post(url, body, {headers: headers});
}

你不需要字符串化你的多个JSON对象

最新更新