2016-02-04 68 views
-1

我正在开发具有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蚂蚁,看看有什么返回。我在这里有一个例子(不同的操作,这是删除操作,而不是登录,但还是一样的结果)

enter image description here

编辑: 只是审查一些链接..显然来自法国的人试图访问我服务器上的一个不存在的文件夹-.-

+0

有人倒我的问题。我做了一些错误的问这个问题吗?请让我知道,所以我可以纠正它,如果是这样的话。 –

+0

DELETE不在你允许的方法中,所以它会给出一个CORS错误(角度状态为0) – Alexander

+0

“delete”只是一个参数,我作为一个变量与我的数据一起发送,它与方法I无关发送或任何东西。 –

回答

1

得到它看起来像您使用的是自签名证书: https://www.ssllabs.com/ssltest/analyze.html?d=ekstroms.xyz&latest

我想你接受了这个在Firefox中和/或将其导入到Firefox信任商店中,但您尚未在您的手机上执行此操作。

+0

这可能是问题! 有没有一种“简单”的方式来免费“正式”签名,你知道? - 我已经开始使用Google,希望能找到一些东西。 –

+0

LetsEncrypt将为您提供免费的官方证书。检查出。 –

1

您必须配置服务器以发送中间证书。

很可能你没有指定'SSLCertificateChainFile`,你的手机无法识别/验证你的证书。

注:如果使用自签名证书,那么它不会自动接受,你要如果可能的话手动安装!

如果您需要为私人/非商业用途的SSL证书,那么你可以从here

+0

我已经按照本指南的指示通过我的CMD窗口使用了“makecert”命令:http://robsnotebook.com/xampp-ssl-encrypt-passwords SSL在Firefox中起作用,正如我在文章中提到的那样,这就是为什么额外的奇怪。 –

+1

如果它是自签名证书,它将不会被您的手机接受! – ZeJur

相关问题