Node.jsv12.0 https请求报错

1.错误信息

write EPROTO 140737037194176:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:

2.问题解析

node.js https模块在v12+中默认使用的TLS1.3,而服务器的TLS不是,如图是TLS1.0。导致报TLS错误

JavonHuang:~ JavonHuang$ curl -iv https://****/mock/52/login
*   Trying 0.0.0.0...
* TCP_NODELAY set
* Connected to test.shuangwutech.com (119.23.207.30) port 443 (#0)
* TLS 1.0 connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
* Server certificate: test.shuangwutech.com
* Server certificate: TrustAsia TLS RSA CA
* Server certificate: DigiCert Global Root CA
> GET /mock/52/login HTTP/1.1
> Host: test.shuangwutech.com
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: openresty/1.13.6.2
Server: openresty/1.13.6.2
< Date: Sat, 16 May 2020 05:45:50 GMT
Date: Sat, 16 May 2020 05:45:50 GMT
< Content-Type: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
< Content-Length: 269
Content-Length: 269
< Connection: keep-alive
Connection: keep-alive
< Access-Control-Allow-Origin: undefined
Access-Control-Allow-Origin: undefined
< Access-Control-Allow-Credentials: true
Access-Control-Allow-Credentials: true

< 
* Connection #0 to host test.shuangwutech.com left intact
{"retcode":"000000","retmsg":"invoke successfully","version":4,"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpcCI6IjEwLjg2LjM3LjIxIiwiZXhwIjoxNTg5Mjc1MDk0LCJ1c2VySWQiOiJBUElfVEVTVCIsInVzZXJuYW1lIjoiQVBJ5rWL6K-VIn0.3M-F5HIM4JKq5vcaBSR5LFKs31gNden3DYRlUpXRqog"}JavonHuang:~ JavonHuang$ 


3.解决方案

添加secureProtocol属性设置,将其TLS版本指定为服务器的版本

const options = {
      hostname: '*****',
      port: 443,
      path: '/mock/52/login',
      method: 'GET',
      secureProtocol:"TLSv1_method",
      headers:{
        'Content-Type': 'Application/json',
      }
    };
    
    const req = https.request(options, (res:any) => {
      res.on('data', (d:any) => {
        resolve(d);
      });
    });
    
    req.on('error', (e:any) => {
      reject(e);
    });
    req.end();

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值