Ionic/Angular $http.post results in a 404, but only on an Android phone, not on an iPhone or in the browser

2,534 views
Skip to first unread message

Steve Sobol - Lobos Studios

unread,
Jul 24, 2015, 10:41:31 AM7/24/15
to Apache Cordova mailing list
This is driving me insane. Angular $http calls result in a 404 Not Found status being returned to my app, but only on Android, not on iOS or while testing.

I have the whitelist plugin installed and I can see, using adb logcat,  an error if I set the whitelist too tightly (I get a message that the URL has been blocked by the whitelist) but when I use a permissive rule like access origin="*", I just get the 404 and nothing is logged.

Simple links using <a href> don't seem to work either.

Details here:

http://forum.ionicframework.com/t/ionic-angular-http-post-results-in-a-404-but-only-on-an-android-phone-not-on-an-iphone-or-in-the-browser/28999

I posted there, and I've gotten some good suggestions but I can't come up with a fix.

Any help you can offer is appreciated. Whoever helps me figure this out, I'll buy you a beer... or coffee... or other beverage of your choice.


--
Lobos Studios - Website and Mobile App Design & Development; IT Support; Computer Maintenance
Toll Free  877.919.4WEB - Apple Valley 760.684.8859 - Los Angeles 310.945.2410 - Cleveland 216.242.4010
www.LobosStudios.com * www.facebook.com/LobosStudios * @LobosStudios

Jammu

unread,
Jul 24, 2015, 12:38:50 PM7/24/15
to phonegap, st...@lobosstudios.com
Just a thought.
If you are seeing an explicit "404" error then that I suspect is coming from the server. I would suggest check on the server side. Perhaps with logging at the tip of the inbound post?

Rob Willett

unread,
Jul 24, 2015, 12:52:26 PM7/24/15
to phon...@googlegroups.com
Steve,

Suggestions would be:

1. Have a look at the Chrome debugger and see if you can the HTTP request leave and return. I'm not next to my 'real' computer so can't check that bit myself. You *should* be able to see the packets and see if a connection has been made. I know Firefox does this very well. 

2 Can you look at the output of the log file from the REST server? Is there anything coming in thats being rejected.

3. Is there another server you can see to check access to. I have often thought I'd set up a simple reflective REST server that simply works and sends back whatever was passed in but slightly modified so you can see its worked. 

I *think* that Android handles whitelists differently to Android. Kerri will be able to answer that question better than me though. I know my limitations there :) 

It has the smell of a permissioning problem. The other option if you have any hair left is to pull that plugin and use the old legacy whitelist plugin to see if that works. Its not a massive change to make to test this out.

I can probably give you another server to test against if that helps but would not be until tomorrow that I can configure it.

Rob.

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steve Sobol - Lobos Studios

unread,
Jul 24, 2015, 1:01:33 PM7/24/15
to phon...@googlegroups.com
That makes perfect sense... but the call works fine on iOS and in my web browser.

Jammu wrote:
--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steve Sobol - Lobos Studios

unread,
Jul 24, 2015, 1:04:34 PM7/24/15
to phon...@googlegroups.com
I'm testing against a website I have running locally on my laptop, and on Android there is no indication anything comes in. Plus, I've tried using another REST service I created for an internal app which *works* on both Android and iOS, and it doesn't work in this new app. The only difference I can come up with is that the working app uses an older Cordova version.

I agree about the probable cause.

I don't need another server - the working REST API I tested against is on a live website, and it's not working in this app either. I mean, simple hyperlinks don't even work - I would have thought it was a whitelist problem but the problem occurs even when I whitelist everything. Thanks for the offer though

Rob Willett

unread,
Jul 24, 2015, 1:12:16 PM7/24/15
to phon...@googlegroups.com
Steve,

I recall issues with different versions of Cordova and the whitelist. I had to upgrade to Cordova 5.x recently from Corodva 3.something. I tried to move slowly through Cordova versions to keep as close to Cordova 3x to minimise impact but in the end had to go to 5.0. I recall a lot of issues with whitelists on the way. In the end I used the legacy whitelist plugin to get the app working knowing I’d have to get the whitelist plugin going ewhrn I had more time. I’d lost the will to live with CORS, Whitelists, Perl and code. This sounds familiar to your frustration :) There's something inside Corodova and whitelists that changed though versions.

I’m away in the North of England and don’t have access to my notes or to my dev machine and can;t recall all the issues but we certainly struggled on this issue for quite some time. I recall CORS being a nightmare to get going. 

I’m not sure I’m helping though. I’ll try and think if I can recall what exact problems we had with cordova and versions. 

Rob. 

Steve Sobol - Lobos Studios

unread,
Jul 25, 2015, 11:14:43 PM7/25/15
to phon...@googlegroups.com
Ok. I was using my phone to debug with Chrome, but it wasn't running a recent enough version of Chrome. SO... I switched to a tablet I bought a few months ago, which does. No clues either in the Chrome inspector or in the massive amounts of crap (that's a technical term!) that flowed out of "adb logcat." But I did finally have the presence of mind to run "ionic serve" using the LAN IP address of my laptop, and then fire up Chrome on the tablet, and point it at that IP.

In the tablet's browser, the request completes with no errors.

In the app, using whatever Android 4.x uses for web views, I get a 404.

The problem isn't solved -- I'm not quite there yet -- but this was an important discovery!

Now I'm wondering if maybe switching to Crosswalk might be a good idea. Thoughts?

Jesse Monroy

unread,
Jul 26, 2015, 12:10:52 AM7/26/15
to phonegap, st...@lobosstudios.com
Steve,
I'm sure that crosswalk will be suggested by a few; they might be right.
However, I have found that crosswalk create a large footprint. If I recall right, it added 20Mb to the App.

Jesse

Jesse Monroy

unread,
Jul 26, 2015, 12:16:45 AM7/26/15
to phonegap, st...@lobosstudios.com, jess...@gmail.com
@Steve,
On your 404 Issue, FWIW, I think your 404 is a JQuery bug. If you are getting a values using a different devices with a different version, then it is definitely NOT a 404.

An http 404 error is page not found. That SHOULD only come from the server, but it appears JQuery/Ionic is trapping that error and putting in it's own response. I know that several off my mobile webbrowser give me annoying responses, instead of "network down", "server failed to respond", or "page not found". All those errors should be different, but the clump them into one generic message.

https://en.wikipedia.org/wiki/HTTP_404

Jesse

Kerri Shotts

unread,
Jul 26, 2015, 3:58:10 PM7/26/15
to phonegap, st...@lobosstudios.com, st...@lobosstudios.com
Hey Steve --

What version of Angular/Ionic are you using? I did a cursory Google search, and some older versions are returning spurious 404s when the actual status is a zero and no response is generated. 

Have you tried making your own XHR call to rule out issues with Angular/Ionic? What response do you get with direct links? Is it the same 404 or something else?


Steve Sobol - Lobos Studios

unread,
Jul 26, 2015, 5:49:28 PM7/26/15
to Kerri Shotts, phonegap
ionic --version says 1.6.1, which is weird. Maybe that's the CLI version; the framework itself is only on 1.0.1.

Direct links don't work. I haven't rolled my own XHR.

It works in Google Chrome on the tablet, though, when I use "ionic serve".

Steve Sobol - Lobos Studios

unread,
Jul 26, 2015, 6:39:09 PM7/26/15
to Kerri Shotts, phonegap
Bare XHR gives me the same result.

I have no whitelist directives in my config.xml; I am using only the CSP meta tag. If I tighten the settings too far, and I pull up the app and look at the console in the Chrome developer tools, I can see the messages that the content is blocked based on the page's policy. If I loosen the settings up, no error,just a 404.

It's either ionicor cordova.


Steve Sobol - Lobos Studios wrote:

jcesarmobile

unread,
Jul 27, 2015, 1:47:33 AM7/27/15
to phonegap, kerri...@gmail.com, st...@lobosstudios.com
"the content is blocked based on the page's policy", seems like an issue with the CSP

Steve Sobol - Lobos Studios

unread,
Jul 27, 2015, 2:19:04 AM7/27/15
to jcesarmobile, phonegap, kerri...@gmail.com
Only if you didn't carefully read what I said. ;)

The web view throws an error if the CSP is set too restrictively. That is behavior that I expect and want to see.

The problem is this: Upon seeing the error, I change the CSP to allow the XHR. When I do that, THAT is when I get the 404 error and nothing in the logs or Chrome's Javascript console to indicate why.

Not on iOS, not on my computer, not on Android when I use "ionic serve" and use Google Chrome on the device. ONLY in the app on Android. Exact same behavior with my Samsung Galaxy Tab 4 tablet and my HTC Droid DNA, both running Android 4.something  (4.4.2 for sure on the tablet, 4.2.something on the phone.)

And so far, I've gotten a lot of good advice here and in the Ionic forum, but no solutions yet.

Gourav Khanna

unread,
Jul 4, 2016, 11:49:42 AM7/4/16
to phonegap, jcesar...@gmail.com, kerri...@gmail.com
I am also facing the same problem. Any solution to this?. 

Rob Willett

unread,
Jul 4, 2016, 11:55:09 AM7/4/16
to phon...@googlegroups.com
Gourav

This thread is a year old and was very specific to Steves problem.

Rather than resurrecting a thread which may or may not be the same problem, I would suggest you raise a new thread detailing what your problem actually is along with your error messages.

Rob

Reply all
Reply to author
Forward
0 new messages