我試圖使用websocket連接到使用react-native的TLS服務器。下面是我的代碼(上+ Android的Windows上運行):React-native websocket TLS連接
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
。這是因爲服務器使用自簽名證書。
有什麼辦法解決這個問題嗎?