Reputation: 23
When I make a request using below code my C# method does not get any data:
$http({
method : 'POST',
url : ...,
data : {
test : 'hello'
})
.then(function (result) {
console.log('success')
}, function () {
console.log('error')
})
In debug mode I'm able to hit the method but no data is passed with the request.
Upvotes: 2
Views: 60
Reputation: 1758
It's a common mistake. Your call should look like:
$http({ method: 'POST',
url: ...,
data: $httpParamSerializerJQLike({ test: 'hello' }),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
)
.then(function () { console.log('success') },
function () { console.log('error') })
Also don't forget to inject $httpParamSerializerJQLike
For more in depth explanation -> AngularJs $http.post() does not send data
Upvotes: 2