【问题标题】:AJAX failing in Android using Cordova使用 Cordova 在 Android 中 AJAX 失败
【发布时间】:2018-02-11 17:55:17
【问题描述】:

我一直在努力对我的 node.js 服务器进行 AJAX 调用,但没有成功。

我做了以下事情:

1) 在我的 node.js 服务器中安装了 cors 包。 AJAX 确实在浏览器中工作。

2) 在 index.html 中添加以下内容安全策略:

<meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://maps.googleapis.com https://163.172.175.135">

3) 在我的 config.xml 中添加了几行:

<?xml version='1.0' encoding='utf-8'?>
<widget id="roda.X.XXXX" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Roda</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="*" />
    <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>
    <engine name="android" spec="^6.2.3" />
    <engine name="browser" spec="^4.1.0" />
    <plugin name="cordova-plugin-geolocation" spec="^2.4.3" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.2" />
</widget>

我错过了什么?

【问题讨论】:

  • 请添加您的确切错误信息
  • 不知何故,只有当我签署 APK 并将其上传到 Google Play 商店时,才会出现问题。如果我要通过电缆传输 APK 并直接在我的手机中运行它,AJAX 就可以了。

标签: javascript android ajax cordova whitelist


【解决方案1】:

后来我发现 AJAX 可以在调试模式下工作,但不能在发布模式下工作。问题是我使用 IP 地址而不是域名连接到服务器,因此 SSL 验证失败。在调试模式下,不验证 SSL 证书。

呸。问题解决了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-19
    • 2015-08-07
    • 2013-08-09
    • 1970-01-01
    • 2015-09-20
    • 2018-03-19
    • 2018-10-07
    • 1970-01-01
    相关资源
    最近更新 更多