1

I am working on IONIC 3/Angular android app. ionic is sending http header origin as file:// for POST and PUT methods of Http calls. It does not add origin to GET method.

The lib i used is '@angular/http'.

We have strict restrictions on the API side. we cannot modify that.

Can any one suggest a solution?

Following is the snippet of http header

    content-type:application/json
    Host:XXXXXXX
    Origin:file://
    User-Agent:Mozilla/5.0 (Linux; Android 7.1.1; Android SDK built 
    for x86 Build/NYC; wv) AppleWebKit/537.36 (KHTML, like Gecko) 
    Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36
    X-DevTools-Emulate-Network-Conditions-Client-Id:XXXXX
    X-Requested-With:com.X.X.X

I also looked the following POSTs and forums. No luck

https://forum.ionicframework.com/t/native-app-is-sending-header-origin-file-which-causes-problems/62388

SO link but no solution.

Ionic native app is sending header Origin:file:// which causes problems

Vijay Ram
  • 285
  • 2
  • 15

1 Answers1

1

I'm not sure if this would solve your problem, but I remember running into this issue when I was making an ionic app awhile back. Looking at how I have my app set up, it looks like I used a proxy to make my http calls on my local. I have a file in the root directory called ionic.config.json which is as follows:

{
  "name": "mobile",
  "app_id": "",
  "type": "ionic-angular",
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "http://your-local-api-address"
    }
  ]
}

and then in the file I use to store API info, I have my URL just set to "/api". There definitely is a solution, but it might be that you're trying to do something ionic can't (easily?) do.. like running your live reload while you're trying to run the app on a native device.

UPDATE

Basically what I wrote above, but found this older posted from a guy who says he has a workaround, here's his input

I managed to find a working solution ! You need to proxy your api server into livereload so that your web app will think the api server is actually the same as your livereload server. Proxy configuration specs are here : https://github.com/driftyco/ionic- cli#advanced-serve-options For example, if your api server is on 192.168.0.1:8888, you need to add this to your ionic.project :

"proxies": [
{
  "path": "/api",
  "proxyUrl": "http://192.168.0.1:8888/api"
}
]

And then, inside your app, you have to make your api calls like if it was local, directly from /api.

Here is the link to the older thread

https://github.com/ionic-team/ionic-cli/issues/89

Cedric Reichenbach
  • 8,970
  • 6
  • 54
  • 89
Jake Boomgaarden
  • 3,394
  • 1
  • 17
  • 31
  • Thanks Jake. I think ionic native http might solve the problem. I tried it but got different other error (related to my eco systems) and I am inclined to add file:// in the origin whitelist of my webserver – Vijay Ram Dec 12 '17 at 15:06
  • something about this just bothers me, lol. I did more looking and found this... it's basically what I'd said but maybe a bit clearer?? I'm going to edit my answer with this additional input, maybe it will help, it's an old post but worth a shot.. otherwise I guess your solution will work – Jake Boomgaarden Dec 12 '17 at 16:44