I'm working on my first android app in Ionic framework. My app should communicate with a REST interface from AngularJS. When I'm testing the app in a browser on my pc then everything works just fine but when I'm running it as an android app from a virtual or a real android device then the POST request doesn't work at all. The GET requests work perfectly. I don't have a clue why it's happening so I appreciate any help!
Part of the code:
$http({
url: address,
method: "POST",
data: jsondata,
transformRequest: false,
headers: { 'Content-Type': undefined }
})
.success(function (data) {
$scope.errormsg = "success";
reloadComments();
})
.error(function (data) {
$scope.errormsg = data;
});
You have to convert all parameters in object then you have to call web services like following example.
$scope.submitForm = function($valid)
{
myobject = {'email' : $scope.user.email, 'pass' : $scope.user.pass};
Object.toparams = function ObjecttoParams(obj)
{
var p =[];
for (var key in obj)
{
p.push(key + '=' + encodeURIComponent(obj[key]));
}
return p.join('&');
};
$http({
url: WSURL + '/login',
method: "POST",
data: Object.toparams(myobject),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data, status, headers, config)
{
}).error(function (data, status, headers, config)
{
});
}
I hope its help to you