Angular $http fails with 404 on Andorid 4.1.1


#1

I am using $http to get JSON data from a remote API.
The program runs fine on Chrome with CORS. But when I build and install the app in my phone, all requests becomes 404, with no request sent to the server.
I have already had the <access origin="*" /> set and given my app the privilege to access the Internet.
the code I am using:
var transform = function(a) { var prefix, s = [], add = function(key, value) { // If value is a function, invoke it and return its value value = (value == null ? "" : value); s[s.length] = encodeURIComponent(key) + "=" + encodeURIComponent(value); }; // If traditional, encode the "old" way (the way 1.3.2 or older // did it), otherwise encode params recursively. for (prefix in a) { add(prefix, a[prefix]); } // Return the resulting serialization return s.join("&").replace('%20', "+"); }; $http({ "method": "POST", "url": SERVICE_URL + "/api/user/login", "headers": { "Content-Type": "application/x-www-form-urlencoded" }, "data": { "url": "", "user[account_id]": usr, "user[password]": pas, "remember_me": 1, }, "transformRequest": transform, }).success(function(){...});


#2

Hey,

first you have to check if the api endpoint for: SERVICE_URL + “/api/user/login” really exist.

404 - Not Found is an indicator that your request url does not exist.

Greets, bengtler.


#3

The program runs well on chrome, with CORS


#4

What mobile browser do you use?


#5

I built the app and installed as apk


#6

Make sure your phone is on the same network as the computer with chrome. If your server isn’t reachable from your carrier’s network then you’ll get the 404 on your phone but not on chrome. For example, this would happen when you’re running a server on an internal network which your workstation is attached to but your phone isn’t.


#7

Finally I solved this problem by adding <access origin=".*" /> and <access origin="http://my.domain.name" />, thank you all.