【问题标题】:HTTPS (SSL) works on firefox but not smartphone appHTTPS (SSL) 适用于 Firefox,但不适用于智能手机应用
【发布时间】:2016-02-04 22:07:01
【问题描述】:

我正在使用 phonegap 和 Ionic 开发一个应用程序,但在使用 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));
    });
}

服务器端

<?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!";
        }
    }
?>

如果你不管怎样,想看看返回了什么。我这里有一个例子(不同的操作,这是一个删除操作而不是登录但仍然是相同的结果)

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

【问题讨论】:

  • 有人否决了我的问题。我问这个问题是不是做错了什么?如果是这种情况,请告诉我,以便我进行更正。
  • DELETE 不在您允许的方法中,因此它会给出 CORS 错误(Angular 中的状态 0)
  • "delete" 只是我作为变量连同我的数据一起发送的一个参数,它与我发送的方法或任何东西无关。

标签: javascript php android angularjs https


【解决方案1】:

看起来您正在使用自签名证书: https://www.ssllabs.com/ssltest/analyze.html?d=ekstroms.xyz&latest

我认为您在 Firefox 中接受了此操作并/或将其导入到 Firefox 信任存储区,但您尚未在手机上执行此操作。

【讨论】:

  • 这可能就是问题所在!您是否知道有一种“简单”的方式可以“正式”免费签名? - 我已经开始在谷歌上搜索,希望能找到一些东西。
  • LetsEncrypt 将为您提供免费的官方证书。检查一下。
【解决方案2】:

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

很可能您没有指定“SSLCertificateChainFile”,您的手机无法识别/验证您的证书。

注意:如果您使用自签名证书,则不会自动接受,如果可能,您必须手动安装!

如果您需要 SSL 证书用于私人/非商业用途,那么您可以从 here 获得它

【讨论】:

  • 我已经按照本指南中的指示在我的 CMD 窗口中使用了“makecert”命令:robsnotebook.com/xampp-ssl-encrypt-passwords SSL 在我的帖子中提到的 Firefox 上工作,这就是它特别奇怪的原因。
  • 如果是自签名证书,您的手机不会接受!
猜你喜欢
  • 2013-09-24
  • 2021-09-02
  • 1970-01-01
  • 1970-01-01
  • 2017-11-25
  • 1970-01-01
  • 1970-01-01
  • 2019-05-06
  • 2018-11-06
相关资源
最近更新 更多