node. js 요청 HTTPS 오류: UNABLETO_VERIFY_LEAF_SIGNATURE \ 의 해결 방법

1765 단어
오류 발견
최근 Nodejs 로 https 요청 을 보 낼 때 \”Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE\” 오류 가 발생 했 습 니 다. 오 류 는 다음 과 같 습 니 다.

events.js:72
throw er; // Unhandled \'error\' event
^
Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE
at SecurePair. (tls.js:1381:32)
at SecurePair.emit (events.js:92:17)
at SecurePair.maybeInitFinished (tls.js:980:10)
at CleartextStream.read [as _read] (tls.js:472:13)
at CleartextStream.Readable.read (_stream_readable.js:341:10)
at EncryptedStream.write [as _write] (tls.js:369:25)
at doWrite (_stream_writable.js:226:10)
at writeOrBuffer (_stream_writable.js:216:5)
at EncryptedStream.Writable.write (_stream_writable.js:183:11)
at write (_stream_readable.js:602:24)

잘못된 이 유 는 상대방 의 디지털 인증서 설정 이 올 바 르 지 않 기 때 문 입 니 다.
해결 방법: reject Unauthorized 인 자 를 false 로 설정 합 니 다.

var https = require(\'https\'); 
 
var options = { 
 hostname: \'www.magentonotes.com\', 
 port: 443, 
 path: \'/\', 
 method: \'GET\', 
 rejectUnauthorized:false 
}; 
 
var req = https.request(options, function(res) { 
 console.log(\"statusCode: \", res.statusCode); 
 console.log(\"headers: \", res.headers); 
 
 res.on(\'data\', function(d) { 
 process.stdout.write(d); 
 }); 
}); 
req.end(); 
 
req.on(\'error\', function(e) { 
 console.error(e); 
});

참고 자료:https://nodejs.org/api/https.html
총결산
이상 은 node. js 가 HTTPS 에 잘못된 해결 방법 을 요청 하 는 것 입 니 다. 본 논문 의 내용 이 여러분 의 학습 이나 업무 에 어느 정도 도움 이 되 기 를 바 랍 니 다. 궁금 한 점 이 있 으 면 댓 글 을 남 겨 주 십시오.

좋은 웹페이지 즐겨찾기