首页 > 解决方案 > 如何在反应本机应用程序中连接到 TLS 套接字连接

问题描述

我正在尝试使用 TLS 1.2 协议连接到 SSL 套接字。这是我的代码:

const client = new WebSocket('wss://<domain-name>');

client.onopen = () => {
    console.log('socket openend');      
};

this.client.onmessage = messageFunction;
this.client.onerror = errorFunction;
this.client.onclose = closeFunction;

并且连接立即关闭。我认为这可能是由于服务器不接受我的证书,所以我曾经react-native-cert-pinner固定所有相关的 SHA256 引脚,但仍然没有运气。

作为参考,以下 node.js 代码可以使用该tls模块:

const tls = require('tls');

const client = tls.connect({ host: '<domain-name>', port: 443 }, () => console.log('connected');

对此问题的任何建议或见解将不胜感激。

标签: react-nativessltcpwebsockettls1.2

解决方案


推荐阅读