【发布时间】:2019-05-21 12:00:25
【问题描述】:
这是我的全部代码
const rp = require('request-promise');
(async () => {
const headers = {
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3',
'Cache-Control': 'no-cache',
Connection: 'keep-alive',
Host: 'www.receita.fazenda.gov.br',
Pragma: 'no-cache',
'Upgrade-Insecure-Requests': 1,
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:64.0) Gecko/20100101 Firefox/64.0',
};
const jar = rp.jar();
try {
const firstAccess = await rp.get('https://www.receita.fazenda.gov.br/Aplicacoes/SSL/ATCTA/CPF/ConsultaSituacao/ConsultaPublica.asp', {
headers,
gzip: true,
simple: false,
strictSSL: false,
jar,
});
console.log(firstAccess);
} catch (e) {
console.log(e);
}
})();
当我运行我的代码时,我收到了这个错误:
UnhandledPromiseRejectionWarning:RequestError:错误:客户端网络 在建立安全 TLS 连接之前套接字已断开
url在浏览器中有效,但是我无法通过nodeJS访问,显然是https证书有问题
有什么方法可以忽略错误并访问它?
【问题讨论】:
-
为什么要使用
request-promise而不是fetch()?
标签: javascript node.js