【问题标题】:SSL Error in nodejs request packagenodejs请求包中的SSL错误
【发布时间】:2018-01-28 07:28:26
【问题描述】:

我正在尝试调用 freecodecamp api @url https://forum.freecodecamp.org/c/getting-a-developer-job.json? 我正在对数据进行一些分析,但是当我使用“请求”npm 包调用此服务时,我收到如下 ssl 错误:

error { Error: write EPROTO 140735782093632:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../deps/openssl/openssl/ssl/s3_pkt.c:1500:SSL alert number 40
140735782093632:error:1409E0E5:SSL routines:ssl3_write_bytes:ssl handshake failure:../deps/openssl/openssl/ssl/s3_pkt.c:659:

    at _errnoException (util.js:1022:11)
    at WriteWrap.afterWrite [as oncomplete] (net.js:867:14) code: 'EPROTO', errno: 'EPROTO', syscall: 'write' }

谁能告诉我问题是什么?当提供--ca-certificate 选项时,wget 调用会提取数据,Web 服务也会在没有任何证书的情况下将数据提供给邮递员。

这是我的代码:

import request from 'request';
import fs from 'fs';

const BASE_URL = 'forum.freecodecamp.org/c/getting-a-developer-job.json?no_subcategories=false&page=1';

request.get(BASE_URL, {
  port: 443,
  agentOptions: {
    ciphers: 'ALL',
    ca: fs.readFileSync('./mycertfile.pem'),
    secureProtocol: 'TLSv1_2_method'
  },
  strictSSL: false
})
.on('response', (response) => {
  console.log('Response is ', response);
}).on('error', (err) => {
  console.log('error', err);
});

【问题讨论】:

    标签: javascript node.js ssl https request


    【解决方案1】:

    除了 URI http:// 不存在外,我没有看到任何问题,在我的环境中我有节点 v10.5.0,并且脚本的稍微修改版本运行良好:

    const request = require('request')
    
    const BASE_URL = 'https://forum.freecodecamp.org/c/getting-a-developer-job.json?no_subcategories=false&page=1'
    
    request.get(BASE_URL, { json: true }, (err, res, body) => {
        if (err) throw('error', err);
        console.log('JSON object is => ', body);
    })
    

    输出到控制台:

    JSON object is =>  { users:
       [ { id: 117390,
           username: 'anthony2025',
    ....
    

    【讨论】:

      猜你喜欢
      • 2017-03-23
      • 1970-01-01
      • 2014-10-15
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      相关资源
      最近更新 更多