Reputation: 117
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;
});
Upvotes: 0
Views: 1661
Reputation: 838
If you're using a newer version of Cordova (or the latest Ionic CLI) to develop your app, you may be experiencing http 404 errors when your app tries to make network requests.
This can be solved quickly with the Cordova whitelist plugin! To install it, just run the following in your project's directory:
ionic plugin add https://github.com/apache/cordova-plugin-whitelist.git
Refer this Link For More Details: http://docs.ionic.io/docs/cordova-whitelist
Upvotes: 1
Reputation: 4782
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
Upvotes: 0