如何将缺少的引荐来源标头添加到Cordova IOS App [英] How to add missing referrer header to Cordova IOS App
问题描述
我正在使用Cordova来构建iOS应用.我使用了离子引擎,这意味着该应用是通过网络服务器提供的在设备上运行.
我的window.location.origin
是"ionic://my-app.com".
由于请求中缺少referrer
标头,因此第三方API(我需要使用该API才能根据用户输入的内容获取地址建议)拒绝了我的HTTP请求.
不可能以编程方式从JS层添加引荐来源网址,但这些无效:
-
<meta name="referrer" content="origin">
-
<meta name="referrer" content="always">
我怀疑问题在于该API使用的是https
,而我的iOS应用使用的是自定义方案(默认方案是ionic://
,无法更改为https).因此,WebView不会添加引荐来源标头.
我该如何解决这个问题?
对于使用ionic的HTTP插件的本机应用程序,我将尝试遵循CORS解决方法.请参阅此处以获取更多详细信息: https://ionicframework.com/docs/faq /cors#1-native-only-apps-ios-android-
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?
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-
这篇关于如何将缺少的引荐来源标头添加到Cordova IOS App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!