I am trying to send a POST request with form data.
Using .save(data)
on $resource('http://localhost:5000/api/auth');
-object sends the following corresponding cURL string (extracted with Chrome):
curl 'http://localhost:5000/api/auth' -H 'Pragma: no-cache' -H 'Origin: http://localhost:63342' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: da-DK,da;q=0.8,en-US;q=0.6,en;q=0.4' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'Referer: http://localhost:63342/public_html/app/index.html' -H 'Connection: keep-alive' -H 'X-FirePHP-Version: 0.0.6' --data-binary '{"username":"admin","password":"mypass"}' --compressed
And my API does not get any form data. However, when I use curl -X POST --data "username=engel&password=mypass" http://localhost:5000/api/auth
my API returns 200 SUCCESS
.
How can I use $resource
to post a similar request as the working one?
The API allows replies that Access-Control-Allow-Origin
http://localhost:63342 is allowed.
EDIT I use the following factory:
factory('AuthResource', ['$resource', function($resource) {
return $resource('http://localhost:5000/api/auth');
}]);
and then I call it with
var login = AuthResource.save(user);
where user is a dict with username
and password