gpt4 book ai didi

node.js - Node 获取:禁用 SSL 验证

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

我有以下代码,它是从快速服务器运行的:

import fetch from 'node-fetch';

let formBody = [];

const dataLogin = {
'username': 'myUser',
'password': 'myPassword'
};

for (let p in dataLogin) {
let encodedKey = encodeURIComponent(p);
let encodedValue = encodeURIComponent(dataLogin[p]);
formBody.push(encodedKey + "=" + encodedValue);
}

formBody = formBody.join("&");

const url = 'https://external-login-api.com';
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': formBody.length
},
body: formBody
});

当我运行代码时,尽管能够在 Postman 中毫无问题地运行请求,但我收到以下错误。

{"message":"request to https://external-login-api.com failed, reason: write EPROTO 7316:error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small:openssl\ssl\statem\statem_clnt.c:1472:\n","type":"system","errno":"EPROTO","code":"EPROTO"}

如何禁用此请求的 SSL 验证?

最佳答案

另一种方法是将您自己的代理设置为获取调用。

const fetch = require('node-fetch');
const https = require('https');

const httpsAgent = new https.Agent({
rejectUnauthorized: false,
});

const response = await fetch(url, {
method: 'POST',
headers: headers,
body: body,
agent: httpsAgent,
});

关于node.js - Node 获取:禁用 SSL 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52478069/

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