Node js Faye 客户端无法正常使用 HTTPS

Node js Faye Client not working properly with HTTPS

我尝试将 node js 与我的应用程序集成,我刚刚测试了 http 服务器它运行良好,但是当我使用如下 https 服务器和我的 index.php 订阅消息时,这不起作用.

Start a server

var https = require('https'),
    faye = require('faye');
var fs = require('fs');

var options = {
  key: fs.readFileSync('/etc/apache2/ssl/apache.key'),
  cert: fs.readFileSync('/etc/apache2/ssl/apache.crt')
};

var server = https.createServer(options),
     bayeux = new faye.NodeAdapter({mount: '/'});

bayeux.attach(server);
server.listen(1337);

Create a client

<script src="faye-browser-min.js"></script>
<script>
var client = new Faye.Client('https://localhost:1337/');

client.subscribe('/messages/*', function(message) {
  alert('Got a message:');
});
</script>

Send messages

我在test.php使用Faye客户端推送消息。

 $adapter = new \Nc\FayeClient\Adapter\CurlAdapter();
 $client = new \Nc\FayeClient\Client($adapter, 'https://localhost:1337/');

 $client->send("/messages/test", array("name" => "foo"), array("token" => "456454sdqd"));

谢谢,

请告诉我如何检查服务器端是否有错误。

我自己解决了问题,问题不在服务器端。它在 php Faye Client 一侧。 Php 客户端适用于 HTTP 服务器,但我需要将其用于 HTTPS 服务器。我做了以下更改然后它工作正常。

/vendor/nc/faye-client/src/Nc/FayeClient/Adapter/CurlAdapter.php

public function postJSON($url, $body)
{

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($body),
            ));

    curl_exec($curl);
    curl_close($curl);
}