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

我试图将js与我的应用程序集成在一起,我刚刚testing了http服务器,它运行良好,但是当我使用https服务器和我的index.php一起订阅消息时,这是行不通的。

启动服务器

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); 

创build一个客户端

 <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> 

发送信息

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

  $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客户端。 该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); }