android - phonegap android ajax over ssl 失败

标签 android jquery cordova ssl jquery-mobile

我使用 Phonegap 和 Jquery Mobile 开发了一个应用程序。由于某些原因,我还需要从 https 域获取数据。在 IOS 上一切正常,但在 Android 上我总是收到以下错误并且请求失败

06-17 17:16:33.890 6079-6154/de.sistecs.einlass E/chromium_net: external/chromium/net/socket/ssl_client_socket_openssl.cc:905: 
[0617/171633:ERROR:ssl_client_socket_openssl.cc(905)] handshake failed; returned -1, SSL error code 1, net_error -107

这是一个简单的示例代码

$(document).on("pageinit", function (event, ui) {
    $("#test").click(function () {
        $.ajax({
            type: "POST",
            url: "https://test.sistecs.de/sismedia/test.php",
            success: function (response) {
                $("#testmsg").text(response);
            }
        });
    });
});

我阅读了数百篇文章,但没有找到解决我问题的方法。 服务器证书https://test.sistecs.de/sismedia/test.php有效。

有人可以帮助我吗?

最佳答案

这似乎是一个跨源问题。

对于 jQuery Mobile,您应该将 $.mobile.allowCrossDomainPages$.support.cors 设置为 true

<script>
    $( document ).on( "mobileinit", function() {
        $.mobile.allowCrossDomainPages = true;
        $.support.cors = true;
    });
</script>

还要确保您的 PHP 页面相应地设置了 header 。例如:

<?php
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET,PUT,POST,DELETE');
    header('Access-Control-Allow-Headers: Content-Type');
    echo "test";
?>

编辑:我没有测试代码,它只是一个例子。根据需要进行调整。

关于android - phonegap android ajax over ssl 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37885245/

相关文章:

android - getcontentresolver() 在服务中返回 null

android - 如何使用 QAndroidJniObject 从 Qt 内部调用 Java 代码?

jquery - Rails 为 .each do |x| 生成图表使用 highcharts 或任何其他图表 API

javascript - Phonegap 互操作能力

cordova - 将 Windows Phone 8 连接到 Weinre

android - 随机文本,缓慢且滞后

android - 避免在 WindowManager 中更新的自定义 View 中的布局更改动画

javascript - 在 Firebase 上用字符串设置 child 的名字

javascript - 适用于除三星互联网外的所有浏览器/设备的逻辑

android - Phonegap 新版本适合 iOS 应用程序开发中的数据库位置