我正在尝试拨打freecodecamp api @url https://forum.freecodecamp.org/c/getting-a-developer-job.json? 我正在对数据做一些分析,但是当我使用'request'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' }
有人可以告诉我这是什么问题吗? wget
调用在提供--ca-certificate
选项时会提取数据,同时网络服务也会向没有任何证书的邮递员提供数据。
这是我的代码:
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);
});
答案 0 :(得分: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',
....