在 Phonegap/cordova Android APP 中使用内容安全策略连接到 REST API 的正确方法是什么
What is the right way of connect to a REST API with content security policy in a Phonegap/cordova Android APP
我已经成功开发了一个 Phonegap 混合应用程序,它在模拟器上运行良好,但在 android 设备上安装时无法 post 到远程服务器。我配置了白名单插件,我的 config.xml 包含
<plugin name="cordova-plugin-whitelist" version="1" />
<access origin="*"/>
<allow-navigation href="http://*/*"/>
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
我的索引页包含
<meta http-equiv="Content-Security-Policy" content="default-src 'self' gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src *; connect-src *">
我正在使用 Cordova 5.3.3
但似乎没有任何效果。
谁能告诉我我做错了什么。
谢谢
尝试以下方法
<plugin name="cordova-plugin-whitelist" source="npm" spec="1.1.0" />
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" />
<preference name="permissions" value="none"/>
我在问题中发布的白名单配置和内容安全策略是正确的,足以在 android 平台上部署混合应用程序连接到远程 API。
问题出在 API 本身,因为该应用程序与其他 API 连接良好。最初我们使用播放框架来开发我们的 API,它在响应混合应用程序上的客户端请求时存在一些问题。
然后我们创建一个 PHP 代理脚本,它从客户端获取请求并将其传递给播放服务器。
就是这样。
我已经成功开发了一个 Phonegap 混合应用程序,它在模拟器上运行良好,但在 android 设备上安装时无法 post 到远程服务器。我配置了白名单插件,我的 config.xml 包含
<plugin name="cordova-plugin-whitelist" version="1" />
<access origin="*"/>
<allow-navigation href="http://*/*"/>
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
我的索引页包含
<meta http-equiv="Content-Security-Policy" content="default-src 'self' gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src *; connect-src *">
我正在使用 Cordova 5.3.3 但似乎没有任何效果。
谁能告诉我我做错了什么。 谢谢
尝试以下方法
<plugin name="cordova-plugin-whitelist" source="npm" spec="1.1.0" />
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" />
<preference name="permissions" value="none"/>
我在问题中发布的白名单配置和内容安全策略是正确的,足以在 android 平台上部署混合应用程序连接到远程 API。
问题出在 API 本身,因为该应用程序与其他 API 连接良好。最初我们使用播放框架来开发我们的 API,它在响应混合应用程序上的客户端请求时存在一些问题。
然后我们创建一个 PHP 代理脚本,它从客户端获取请求并将其传递给播放服务器。
就是这样。