-1

I am facing a very peculiar issue, when using Ionic 3 in iOS, I am trying to connect to a different domain [ddd.com], and since Ionic 3 uses WebKit, it changes the hostname to localhost:8080 in iOS.

This created a CORS issue, I was able to fix it by adding Allow-Control-Allow-Origin: http//localhost:8080 and Access-Control-Allow-Credentials: true.

Though this seems to work it had one issue, it never works the "first time" i.e when the app is downloaded and opened for the very first time. But it works when the app is killed and re-opened.

Any clue to un-wrap this tangly dangly mystery would be much appreciated.

  • Krishna Sagar
Krishna sagar
  • 145
  • 1
  • 8
  • Could you share the exact error message and/or the response headers? – Klajbar Feb 05 '18 at 20:10
  • Response from server has these in the response Set-Cookie: sid=fRjoJmlibZOzzdXL; path=/;\r\n Set-Cookie: lsid=veMeaxtTknpcZinq; expires=Fri, 01-Jan-2046 00:00:01 GMT; path=/\r\n In the next HTTP request to the server we don’t see the cookie having the above value. Infact Cookie in the header is not even present. – Krishna sagar Feb 06 '18 at 10:30
  • Does the cokkie uses sid or token based ? – UserM Feb 06 '18 at 10:39

1 Answers1

3

Ionic3 use WKWebview where it enforces security for Ajax request. In 2 ways it can be rectified.

First solution: Use UIWebview instead of WKWebView. But these solution costs the performance of the App.

Second Solution Instead of angular HTTP call, Use native HTTP call. Use this plugin for easy implementation.

https://github.com/sneas/ionic-native-http-connection-backend

Community
  • 1
  • 1
  • The second solution solved my problem, I was about to re-write my Httpmodule but then this plugin https://github.com/sneas/ionic-native-http-connection-backend saved me a lot of time !!. Thanks a lot for the help – Krishna sagar Feb 07 '18 at 15:19