I tried to make a post request from ionic to web api this way
ionic code
$http({
url: 'http://localhost:1449/api/IonicApi',
method: "POST",
data: {
firstName : "a",
lastName : "b",
email : "ab@ab.com"
},
headers: { 'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8" }
}).then(function (response) {
// success
$ionicPopup.alert({
title: 'Your Name is '+$scope.man.firstName + ' '+$scope.man.lastName,
template: 'It might taste good'
})
}, function (response) { // optional
// failed
console.log('failed');
});
and the c# part is
public IHttpActionResult Post(tblPerson person)
{
db = new MobileDBEntities();
db.tblPersons.Add(person);
db.SaveChanges();
return Ok();
I tried from postman to post data it was working. But from Ionic it is passing null data of object
What wrong did I make here?