【发布时间】:2016-11-04 15:50:08
【问题描述】:
我正在尝试使用 websocket 连接到使用 react-native 的 TLS 服务器。下面是我的代码(在 windows + android 上运行):
var ws = new WebSocket('wss://hub.fingi-staging.com:20020',{
rejectUnauthorized: false
});
ws.onopen = () => {
// connection opened
ws.send('something'); // send a message
};
ws.onmessage = (e) => {
// a message was received
console.log('message : ' + e.data);
};
ws.onerror = (e) => {
// an error occurred
console.log('error:'+e.message);
};
ws.onclose = (e) => {
// connection closed
console.log('close:'+e.code, e.reason);
};
但是,它失败了:error:java.security.cert.CertPathValidatorException: Trust anchor for certification path not found。这是因为服务器使用自签名证书。
有没有办法解决这个问题?
【问题讨论】:
标签: ssl websocket react-native react-native-android