gpt4 book ai didi

rejectUnauthorized 为 false 的 Node.JS 请求

转载 作者:搜寻专家 更新时间:2023-10-31 22:49:48 25 4
gpt4 key购买 nike

我正在尝试使用 Node.js 的 request 模块来制定 HTTPS GET 请求。使用https模块对应的代码如下:

var https = require('https');

var options = {
hostname: url,
path: path,
rejectUnauthorized: false,
secureProtocol: 'TLSv1_method',
port: 8443,
method: 'POST'
};

https.get(options, function(response) {
var body = '';
response.on('data', function(chunk) {
body += chunk.toString();
});
response.on('end', function() {
var content = JSON.parse(body);
console.log(content);
});
});

我尝试使用 request 模块重写这段代码,如下所示:

var request = require('request');

var options = {
url: url,
strictSSL: false
}

request.get(options, function(error, response, body) {
if (error) {
console.log(error);
} else {
console.log(body);
}
});

但是,这给了我一个错误 { [Error: socket hang up] code: 'ECONNRESET', sslError: undefined }

什么是 request 等同于 rejectUnauthorized: false

最佳答案

这可能会对您有所帮助。

let request = require( 'request' ).defaults({rejectUnauthorized:false});

关于rejectUnauthorized 为 false 的 Node.JS 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36588963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com