Although you have a solution, there are several ways to POST simple string data (rather than an object) to the Web API .
Let's say you have a POST API like this (in Test ApiController)
public void Post([FromBody]string value) {
From AngularJS you can post this method e.g.
(1) data as JSON (default)
$scope.Test = function () { $http({ method: "POST", url: "/api/Test", data: JSON.stringify("test") }); };
The default is Content-Type: application/json . And the server will process the data as JSON. If you look at the request, you will see that the request body is a simple string, for example
"test"
For complex objects, you will see their formatted JSON.
(2) as application/x-www-form-urlencoded (as in your example)
$scope.Test = function () { $http({ headers: {'Content-Type': 'application/x-www-form-urlencoded'}, method: "POST", url: "/api/Test", data: $.param({ "": "test" }), }); };
Here we explicitly specify the content type as application/x-www-form-urlencoded , so we must send data in this format (like the url query string). And here, the blank key in the data simply satisfies the Web API requirements of Web API weird model binding! The received data will be encoded as
=test
which we did with $.param({ "": "test" }) . One of the reasons for this, FromBody used primarily to send an object , rather than simple primitive values.
So, the main problem with your code was: you specified the Content Type: application / x-www-form-urlencoded, and you sent the data as JSON!