Websocket SSL 连接 [英] Websocket SSL connection
问题描述
我正在尝试测试一个安全的 websocket,但我遇到了问题.这是我的测试:
I am trying to test a secure websocket but I'm having trouble. Here is my test:
var WebSocket = require('ws');
describe('testing Web Socket', function() {
it('should do stuff', function(done) {
var ws = new WebSocket('wss://localhost:15449/', {
protocolVersion: 8,
origin: 'https://localhost:15449'
});
ws.on('open', function() {
console.log('open!!!');
done();
});
console.log(ws);
});
});
这是ws"创建后的日志:
Here's the log of "ws" after it's created:
{ domain: null,
_events: { open: [Function] },
_maxListeners: undefined,
_socket: null,
_ultron: null,
_closeReceived: false,
bytesReceived: 0,
readyState: 0,
supports: { binary: true },
extensions: {},
_isServer: false,
url: 'wss://localhost:15449/',
protocolVersion: 8 }
我没有从打开中获取日志.我在本地运行该项目,当我使用 Chrome Advanced Rest Client 工具时,我能够正常连接.
I don't get a log back from open. I am running the project locally and when I use the Chrome Advanced Rest Client tool I am able to connect just fine.
我错过了什么吗?请帮忙.
Am I missing something? Please help.
我添加了 ws.on('error')
并且它注销了 { [Error: self signed certificate] code: 'DEPTH_ZERO_SELF_SIGNED_CERT' }
我也试过按照这个 代码 但得到同样的错误.
I added ws.on('error')
and it logged out { [Error: self signed certificate] code: 'DEPTH_ZERO_SELF_SIGNED_CERT' }
I've also tried following this code but get the same error.
推荐答案
https
模块拒绝您的自签名证书(正如人们所希望的).您可以通过传递 rejectUnauthorized: false
选项(WebSocket
将传递给 https
)来强制它停止检查:
The https
module is rejecting your self-signed cert (as one would hope). You can force it to stop checking by passing a rejectUnauthorized: false
option (which WebSocket
will pass down to https
):
var ws = new WebSocket('wss://localhost:15449/', {
protocolVersion: 8,
origin: 'https://localhost:15449',
rejectUnauthorized: false
});
这篇关于Websocket SSL 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!