I'm attempting to post a new user to my servers using rectangular. The post is failing because the post body is always blank.
var userData = data.logged_in_user;
var userDetails = {
id: userData.pk,
username: userData.username,
pic: userData.profile_pic_url,
full_name: userData.full_name
};
Restangular.all('users').post(userDetails)
.then(function() {
console.log('Success')
})
.catch(function() {
console.log('Error')
});
I have no interceptors in my code, but when I do add one and log out the values, the element value is populated with userDetails.
This is the HTTP request:
OPTIONS /api/users HTTP/1.1
Host: myserver.com
Accept-Language: en-us
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12F69 (2019885536)
Accept: */*
Referer: http://192.168.1.67:8100/?restart=250098
Access-Control-Request-Method: POST
Connection: keep-alive
Access-Control-Request-Headers: accept, origin, content-type
Content-Length: 0
Origin: http://192.168.1.67:8100
Accept-Encoding: gzip, deflate
is it possible that you have a problem with same domain restriction ? your request is not a POST but an OPTIONS request. Usually the browser use this request to check permissions and other info from server.
Usually when you work in a browser you can make request only to the same domain of your pages (file:/// in case of cordova). There are ways to overcome this limitation, CORS is one of theme. They are just headers sent from server that tells the browser to trust him and the browser use a OPTIONS request to load those headers (more here http://en.wikipedia.org/wiki/Cross-origin_resource_sharing).
When you work inside cordova you can specify to disable the same domain limitation using a simple tag in your config.xml
<access origin="*" />
But if you are tyring your code into a browser or you don't have specified this tag the cordova view requests headers with that OPTION request.
Hope this helps