gpt4 book ai didi

node.js - NodeJS 请求 promise ERR_TLS_CERT_ALTNAME_INVALID

转载 作者:太空宇宙 更新时间:2023-11-04 01:36:42 24 4
gpt4 key购买 nike

尝试使用 HTTPS 向网站发送请求时,我收到以下错误:ERR_TLS_CERT_ALTNAME_INVALID

我尝试将 insecure: true 添加到我的请求负载中,但这没有任何作用,我也尝试添加 rejectUnauthorized: false 但这给了我一个 400 错误 - 错误的请求。

var rp = require('request-promise').defaults({jar: true});
var sess = rp.jar();

function SendRequest() {
let link = "https://www.example.com";
payload = {
method: 'GET',
jar: sess,
json: true,
url: link,
headers: {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
'Connection': 'keep-alive',
'Host': link,
'Upgrade-Insecure-Requests': '1', // removed this nothing changed
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Mobile Safari/537.36'
},
gzip: true
// tried adding insecure: true (did nothing) & rejectUnauthorized: false (returned 400 error)
}
rp(payload)
.then(function(json) {
console.log(json)
})
}

我希望请求能够顺利通过。

最佳答案

事实证明,400 错误实际上与 header 'Host': link, 相关,删除此 header 并添加 rejectUnauthorized: false 后一切正常。

关于node.js - NodeJS 请求 promise ERR_TLS_CERT_ALTNAME_INVALID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54355341/

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