$http({method: 'POST', url: 'http://localhost:5001/products', data: {token: $scope.product.token}}).success(
function () {
alert('success');
}
);
In the pyramid side, request.POST show that NOVars: Not a form request. Not an HTML form submission( Content-Type: application/json)
I am using cornice to provide my api(/products) and I thinks it is pyramid's problem.
Does anyone have a solution?
Angular sends the post body (data) as
application/json
while forms are normally sent asapplication/x-www-form-urlencoded
. Pyramid parses the body and let you access it inrequest.POST
when it's encoded as a normal form.It is not be possible to represent every data encoded the Angular way (json) as a key/value pair like is provided by pyramid API.
Solution on Pyramid side
It can be solved per view or globally
Per view
This is the pyramid way and the most flexible way to handle this.
Globally
Pyramid can most likely be set to assume a body encoded as
application/json
is an object and its properties be put in request.POST.Solution on Angular side
As with the pyramid side, it can be solved per request and globally.
Per request
You need to send the data the way forms are normally sent:
Globally
To send posts as form by default, configure the $httpProvider to do so.
Then include this module in your app: