当尝试使用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)
})
}我期待着请求通过,没有任何问题。
发布于 2019-01-26 04:39:27
事实证明,400错误实际上与头文件'Host': link,有关,删除此文件并重新添加rejectUnauthorized: false后,一切都正常工作。
https://stackoverflow.com/questions/54355341
复制相似问题