Javascript HTTPS(SSL)适用于firefox,但不适用于智能手机应用程序
我正在使用phonegap和Ionic开发一个应用程序,但在使用HTTPS(SSL)时遇到了困难。我对这为什么不起作用感到困惑。 它就像Firefox上的符咒,但当我在手机上运行它时,它就不起作用了 如果我使用普通的HTTP,它可以正常工作,但HTTPS不能,我认为这与用于SSL的端口443有关,但不知道如何在我的智能手机(android)上检查它 问题: 为什么HTTPS不能在我的智能手机上工作?我如何让它工作 登录代码:Javascript HTTPS(SSL)适用于firefox,但不适用于智能手机应用程序,javascript,php,android,angularjs,https,Javascript,Php,Android,Angularjs,Https,我正在使用phonegap和Ionic开发一个应用程序,但在使用HTTPS(SSL)时遇到了困难。我对这为什么不起作用感到困惑。 它就像Firefox上的符咒,但当我在手机上运行它时,它就不起作用了 如果我使用普通的HTTP,它可以正常工作,但HTTPS不能,我认为这与用于SSL的端口443有关,但不知道如何在我的智能手机(android)上检查它 问题: 为什么HTTPS不能在我的智能手机上工作?我如何让它工作 登录代码: $scope.login = function(name, passw
$scope.login = function(name, password) {
$scope.type = 'login';
// Data to be sent to the database
var data = JSON.stringify({
type: $scope.type,
name: name.toLowerCase(),
password: password
});
var useSSL = false;
// Call httpPost from app.js with this scope and the data to be inserted
$scope.httpPost($scope, data, $scope.type, useSSL);
};
功能:httpPost
$rootScope.httpPost = function(scope, question, type, SSL) {
var urlBase = "http";
if (SSL) urlBase = "https";
var request = $http({
method: "post",
url: urlBase+"://mydomain.xyz/myproject/api.php",
crossDomain : true,
data: question,
headers: { 'Content-Type': 'application/json' }
});
/* Successful HTTP post request or not */
request.success(function(data) {
if (type == "login"){
// Confirm it's a valid token
if(data.length == 10){
showAlert('confirmation', 'you are now online');
}
else{
showAlert('Try again', 'wrong credentials');
}
}
})
.catch(function(data, status, headers, config) {
// No response from server
// This is what triggers and the data returned is useless
showAlert('Ooops', JSON.stringify(data));
});
}
服务器端
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: X-PINGOTHER');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Retrieve the incoming data
$postdata = file_get_contents("php://input");
// Check if the data is defined
if (isset($postdata)) {
// Parse the incoming data
$request = json_decode($postdata);
// Connect to database
include 'connect.php';
$db = Database::getInstance();
$db->connect();
// Login attempt and non-empty parameters
if ($request->type == "login" && $request->name != "" && $request->password != "") {
// Verify if the password matches
// Set token
// Execute the SQL
// Return the token
}
echo "Missing parameters!";
}
}
?>
如果你不顾一切,想看看有什么回报。。我这里有一个例子(不同的操作,这是一个删除操作而不是登录,但结果仍然相同)
编辑:
刚刚删除了一些链接。。显然,来自法国的人试图访问我的服务器上不存在的文件夹-。-您必须配置服务器以发送中间证书 很可能您尚未指定“SSLCertificateChainFile”,并且您的手机无法识别/验证您的证书 注意:如果您使用自签名证书,则不会自动接受该证书,如果可能,您必须手动安装
如果您需要用于私人/非商业用途的SSL证书,那么您可以从获取该证书,看起来您正在使用自签名证书:
我猜你在Firefox中接受了这一点,并/或将其导入Firefox信任商店,但你还没有在手机上这样做。有人否决了我的问题。。问这件事我做错什么了吗?请让我知道,以便在这种情况下我可以更正它。删除不在您允许的方法中,因此它将给出一个CORS错误(角度状态为0)“删除”只是我作为变量随数据发送的一个参数,它与我发送的方法或任何东西无关。我使用了“makecert”命令通过我的CMD窗口,如本指南所述:SSL在Firefox上工作,正如我在文章中所提到的,这就是为什么它特别奇怪。如果它是自签名证书,您的手机将不会接受它!这可能就是问题所在!你知道有没有一种“简单”的免费“正式”签名方式我已经开始谷歌搜索,希望能找到一些东西。LetsEncrypt将为您提供免费的官方证书。请查看。