对api.bitbucket.org的Node.js SSL / HTTPS请求获取奇怪的SSL错误

时间:2019-05-22 01:45:04

标签: node.js ssl https

我遇到了这个奇怪的错误:

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

1 个答案:

答案 0 :(得分:0)

我有port: 80,但是对于默认的SSL,它应该为port: 443 ...,因此您可以省略port参数。