我开发了一个带有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的证书是有效的。
有人可以帮助我吗?
答案 0 :(得分:1)
这似乎是一个Cross Origin问题。
使用jQuery Mobile,您应将 $。mobile.allowCrossDomainPages 和 $ .support.cors 设置为 true
<script>
$( document ).on( "mobileinit", function() {
$.mobile.allowCrossDomainPages = true;
$.support.cors = true;
});
</script>
另外请确保您的PHP页面相应地设置标题。例如:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET,PUT,POST,DELETE');
header('Access-Control-Allow-Headers: Content-Type');
echo "test";
?>
编辑:我没有测试代码,这是一个例子。根据需要进行调整。
答案 1 :(得分:0)
var myJson = {
'Par1': 'par'
};
$.ajax({
url: baseUrlAjaxServices + "/....",
data: JSON.stringify(myJson),
method: "POST",
crossDomain: true,
dataType: 'json',
contentType: 'application/json',
})
.done(function (data) {
//...
}).fail(function (error) {
console.log(error);
});