3
votes

I am using Cordova to build an iOS App. I use the Ionic engine meaning that the app is served from a webserver running on the device.

My window.location.origin is "ionic://my-app.com".

A third party API (that I need to use in order to fetch an address suggestion based on what the user types) rejects my HTTP requests because the referrer header is missing in the request.

It's not possible to programmatically add a referrer from the JS layer and these did not work:

  • <meta name="referrer" content="origin">

  • <meta name="referrer" content="always">

I suspect that the issue is that the API is using https and my iOS App is using a custom scheme (the default one is ionic:// and cannot be changed to https). For this reason the referrer header is not added by the WebView.

How can I solve this issue?

2
A 50 bounty will be given to anyone that helps solve this.Gabe
Is it only that one API that restricts your access because of a missing referrer? You may not be desperate enough at this point, but routing your request through a server that you control to forward the request will work.JM-AGMS
Yep, that's my last resort. It's the only API that currently restrics access because of the missing referrer. :(Gabe
If you control the third party API, you could send custom headers.nice_dev
I don't control the third party APIGabe

2 Answers

1
votes

I'd try following the CORS workaround for native apps that uses the HTTP plugin from ionic. See here for more details: https://ionicframework.com/docs/faq/cors#1-native-only-apps-ios-android-

1
votes

if you are using the webview package cordova-plugin-inappbrowser you can integrate this Pull Request in your code and you will be able to set a custom header with a custom value: https://github.com/apache/cordova-plugin-inappbrowser/pull/363

I have done it and it works.