I’ve created an ASP.Net API Controller to which I’m trying to make a POST request with Angular. The request reaches my controller method, but the parameter value is null.
My Angular code:
$http({ method: 'POST', url: '/api/Contents', data: "value=foobar", headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).
success(function(data) {
}).
error(function(data, status, headers, config) {
});
I’ve also tried with json (Json is what I want in the end):
$http({ method: 'POST', url: '/api/Contents', data: { "foo": "bar", "foo2": "bar2" }, headers: { 'Content-Type': 'application/json'} }).
success(function(data) {
}).
error(function(data, status, headers, config) {
});
My (very simple) Controller method looks like this:
public void Post([FromBody]string value)
{
//But Value is NULL!!!!!!
}
Below are some values from my request headers cut out from Chrome (the ones I thought could be interesting:
- Request Method: POST
- Status Code: 204 No Content
- Accept: application/json, text/plain, /
- Content-Type: application/x-www-form-urlencoded
- X-Requested-With: XMLHttpRequest
- Form Dataview sourceview URL encoded
- value: foobar
- Server: Microsoft-IIS/8.0
- X-AspNet-Version: 4.0.30319
What am I missing?