I am experiencing very strange issue when building and running ionic app. I am calling Login API from server and it work very well in browser, when run as
$ionic serve --lab
But when app is installed in Android, it gives 403 error, and does not give any other information about error code, probably, i am not sure how to get browser console log in android hybrid app.
I have login function as follows
login: function(user) {
var deferred = $q.defer();
$http.post(SERVER_URL + '/auth/login', {
username: user.username,
password: user.password
}).success(function(response, status, headers, config) {
if (response.data && response.data[0]) {
Auth.setToken(response.data[0].token);
Auth.setUserId(response.data[0].id);
deferred.resolve(response);
} else {
deferred.reject(response);
}
}).error(function(response, status, headers, config) {
deferred.reject(response);
});
return deferred.promise;
}
However, all the get request works properly.
I ran into this recently, I couldn't POST anything from the app running on my iPhone or from the simulator without receiving a 403, but it did work directly from any browser including the one on my phone and using Postman-chrome plugin.
This seemed to be an issue with any POST request from the Ionic app: it was sending the Origin
header as file://
. With a Play Framework 2.4 backend, I had to disable the CORSFilter
completely (removing play.http.filters
from application.conf) for it to work. I'm going to investigate further and maybe provide some more details later.
X-Requested-With
& Content-Type
header settings, <allow-navigation href="*"\>
, and nothing worked. The access element provides your app with access to resources on other domains in particular, it allows your app to load pages from external domains that can take over your entire webview. Just add this in config.xml
<access origin="*" subdomains="true"/>
It worked when i run app as
$ionic run --livereload android
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With