알뜰살뜰 정보/Node

https request 통신

쉬고싶은 거북이 2020. 10. 13. 17:34

에러발생

Got a response:  Bad Request

This combination of host and port requires TLS.


const http = require('http')
// http 모듈을 https 모듈로 바꿔줘야합니다.
const https = require('https')


에러발생

Error: self signed certificate

    at TLSSocket.onConnectSecure (_tls_wrap.js:1058:34)

    at TLSSocket.emit (events.js:198:13)

    at TLSSocket.EventEmitter.emit (domain.js:448:20)

    at TLSSocket._finishInit (_tls_wrap.js:636:8)


해결방법


function https_request(ipstring) {
     const options = {
         hostname: 'localhost',
         port: 8080,
         method: 'GET',
         rejectUnauthorized: false,
         requestCert: true,
     };