Hello I have an ionic/angular project which has some http GET requests. It was fully working on browser, iOS and Android, where the HTTP request would get executed and details displayed in my ionic UI. However as of recently, after updating Android Studio etc, I noticed that my android native version is broken and I am not getting any HTTP requests.
Every time a GET request is executed I see this error in the log →
I have a service running the foreground, where I can make those http calls in the emulator’s browser and the requests are coming in, and the service works just fine… the ionic app though is empty. Any advice would be appreciated.
I created a fresh ionic project and used itunes api… seems to work, I then added the itunes api to my project and it is giving me the same error… So it seems like it is to do with my project… some settings… somewhere…
Either way, you could attempt to remove the platform and add it back?
Kind of a forceful way to fix it, but if there’s some configuration issue, that could reset it.
I tried both, I also checked network config of the emulator, however, it makes no difference with the localhost. (127.0.0.1 and 10.0.2.16 for emulator)
Hi man, after hours of debugging… I noticed that there is an issue with polling… it works perfectly fine on iOS… I’m using rxjs and rxjs/operators to implement my poll…
hi I am getting a similar error .I am using ionic 5 . Everything works fine on the browser . The app connects to nodejs back-end server . The HTTP calls work fine in the browser but nothing is returned in android . I did not really understand what worked for you . @mhartington@ThonyFD12
I have implemented CORS in the back-end server to set headers.
var oReq = new XMLHttpRequest();
oReq.open("GET", "http://www.example.org/example.txt");
oReq.send();
I am using XMLHttpRequest because ionic’s native library is not supported to run in browser . So it always requires the app to be run in an actual device which increases testing time .
XMLHttpRequest this works well in both browser and android device . I have not tested it on ios .
Hope this helps !!!
PS : Also latest Android versions do not support http use https .
Thanks - are you sure that the Angular HttpClient does not work on Android? Is that documented anywhere? (we’ve always used it without issues - though maybe that’s the cause of the issues I am having now?)
havent found any documentation that says so .
just that it did not work for me . Would like to add that surprisingly on one of the devices (Motorolla android phone) the http client from angular did work Also this device had older android version (< Pie) . So to say that Angular HttpClient does not work on Android i might not be 100% correct .
But in all other devices the Angular HttpClient was not returning any response. So i had to take resort to the above two libraries.
If angular HTTP Client works for you please share .
Yes the solution is to ensure you allow cors in your json config file, this will allow you to make your http requests. I noticed mine was off in my project and hence why it was working everywhere except for Android