SunMan SunMan - 26 days ago 21
AngularJS Question

ionic $http post not sending data

I am trying to post data to a web service but the data is missing.

Here is the code

var product = {
CategoryID: 'test'
};

$http({
url: URL,
method: "POST",
data: product,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data,status,headers,config) {
console.log(data);
})
.error(function(data,status,headers,config) {
console.log(data);
});


The POST data on the server is empty.

I have set up Access-Control-Allow-Origin,Access-Control-Allow-MethodAccess-Control-Allow-Headerss and Access-Control-Allow-Headers on the server.

This API works fine when tested through Postman

Answer

For your issue try a look at this one How do I POST urlencoded form data with $http in AngularJS? - you probably need to transform your request in order to sent in via $http service with the required content type.