我正在开发具有phonegap和Ionic的应用程序,并且HTTPS(SSL)有困难。我对为什么拒绝工作感到困惑。 它在Firefox上像一个魅力,但当我在手机上运行它时,它不起作用。HTTPS(SSL)适用于firefox,但不适用于智能手机应用
如果我使用正常的HTTP,但它工作正常,但HTTPS不,我认为它与用于SSL的端口443有关,但不知道如何在我的智能手机(android)上检查它。
问题: 为什么HTTPS无法在我的智能手机上工作,我如何才能使它工作?
登录代码:
$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));
});
}
Serverside集团
<?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!";
}
}
?>
如果你不顾一切,W蚂蚁,看看有什么返回。我在这里有一个例子(不同的操作,这是删除操作,而不是登录,但还是一样的结果)
编辑: 只是审查一些链接..显然来自法国的人试图访问我服务器上的一个不存在的文件夹-.-
有人倒我的问题。我做了一些错误的问这个问题吗?请让我知道,所以我可以纠正它,如果是这样的话。 –
DELETE不在你允许的方法中,所以它会给出一个CORS错误(角度状态为0) – Alexander
“delete”只是一个参数,我作为一个变量与我的数据一起发送,它与方法I无关发送或任何东西。 –