How to add missing referrer header to Cordova IOS

2020-03-30 02:08发布

问题:

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?

回答1:

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-