首页 > 解决方案 > 对 api.bitbucket.org 的 Node.js SSL / HTTPS 请求出现奇怪的 ssl 错误

问题描述

我收到这个奇怪的错误:

Making request to bitbucket api at path: /2.0/repositories/interos/eco-system-globe/commit/116c82c81b8d3e1b8c2fd3f352510fd09e66a02e
***Request stream error***: Error: write EPROTO 139717438125888:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:

    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:83:16) {
  errno: 'EPROTO',
  code: 'EPROTO',
  syscall: 'write'
}

我的代码很简单:

 const pth = `/2.0/repositories/${fullRepoName}/commit/${sha}`;

  console.log('Making request to bitbucket api at path:',pth);

  const newReq = https.get({  // formerly get
    protocol: 'https:',
    port: 80,
    hostname: 'api.bitbucket.org',
    path: pth,
    headers: {

      'Authorization': `Basic ${bitbucketBase64}`,
      'Auth': `Basic ${bitbucketBase64}`
    }

  }, r => {


    const v = {
      data: ''
    };

    r.on('data', d => {
      v.data += String(d || '');
    });

    r.once('end', () => {

      console.log('response ended:', r.statusCode);
      cb(null, v);

    });

  });


  newReq.once('error', e => {
    console.error('***Request stream error***:', e);
  });

  // newReq.write(stringified);
  newReq.end();

有人知道那是什么吗?我在 Node.js 版本12.2.0

标签: node.jssslhttps

解决方案


我有port: 80,但它应该是port: 443……对于 SSL,这是默认设置,所以你可以省略 port 参数。


推荐阅读