0

I am trying to consume HTTP services from an external location but only get ERR_CONNECTION_TIMED_OUT because the request never gets to the server.

The app have been built with ionic 1 and angularjs, using angular-resource to consume services

After reading several SO questions I end up setting up my app as follows:

config.xml

<allow-navigation href="*" />    
<access origin="*" />

index.html

<meta http-equiv="Content-Security-Policy" content="default-src 'self' http://server_ip:8080 data: gap: *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

of course, service_ip is the real server ip address and it accepts HTTP requests as I have been able to consume them using REST clients.

Other considerations:

  • The app is built and launched using command ionic run android.
  • I am using plugin cordova-plugin-whitelist. (I removed and added it again following several SO answers... without success).
  • Also using plugin angular-resource for HTTP requests. Requests are correct as I have tested them using local machine ip and they work, problems came after changing that ip to the server ip.

It looks like a CORS problem, I expected to solve it via meta tag in index.html file but the behaviour is the same even when I set up:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

Any help will be appreciated.

juankysmith
  • 11,839
  • 5
  • 37
  • 62
  • sorry are you testing on IOS or on ANDROID ? – federico scamuzzi May 05 '17 at 12:05
  • try using 'cordova run android' – Edison Augusthy May 05 '17 at 12:12
  • Try check this link http://stackoverflow.com/questions/30326148/cordova-ionic-http-request-not-processing-while-emulating-or-running-on-dev – digit May 05 '17 at 12:38
  • @digit I have already tried that solution but didn't work. In fact the second meta tag is the same. – juankysmith May 05 '17 at 17:38
  • I guess it must be network issue. Check the firewall and also try ping from your phone to your computer what is the status. Also you must connect using same network if you want to test using localhost. – digit May 05 '17 at 23:14
  • @digit Sorry, maybe I have explained myself wrong, I am testing the app using command "ionic run android" in my computer but the HTTP request are sent to a external server with ip "server_ip" in the question. I am able to consume those services using REST clients – juankysmith May 06 '17 at 08:14
  • @federicoscamuzzi android – juankysmith May 06 '17 at 08:14
  • Did you try if you can replicate the problem on a real device? it usually is common that CORS issues raises when you try to run any sort of http requests on a simulator, and that's why you should use a proxy instead to test these: http://ionicframework.com/docs/v1/cli/test.html#service-proxies – briosheje May 06 '17 at 09:16
  • @briosheje I run the app on a real device connected via USB debugging. ionic run android -> myapp-debug.apk – juankysmith May 06 '17 at 09:20
  • @juankysmith: I'm not really sure how this could happen then, since by definition whenever you run the application on a real device you **don't** need any sort of configuration to consume any HTTP service, since CORS issues don't exists at all when you use a real device. Perhaps you may find something useful here: http://blog.ionic.io/handling-cors-issues-in-ionic/ . It's strange though, maybe the problem is DNS-related? It doesn't make much sense that it's throwing a connection timeout. – briosheje May 06 '17 at 09:42
  • Also, please check in android manifest – digit May 06 '17 at 18:13

1 Answers1

0

Finally, the problem was on my device. I had to upgrade Google's WebView application in my device to get it work.

Solution was found here

juankysmith
  • 11,839
  • 5
  • 37
  • 62