我使用 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/