자체 서명된 서버에서 기본 인증을 사용하는 Node.js HTTP 요청

자체 서명된 서버에서 기본 인증을 사용하는 Node.js HTTP 요청

자체 서명된 인증서를 사용하여 웹 서버에서 기본 응답을 얻기 위해 다음 코드를 사용하고 있습니다. 기본 인증이 필요합니다.

아래 코드를 통해 시도하고 있습니다.Node.js(모듈 사용 http) 그러나 몇 초 후에 실패합니다. 서버로부터 아무런 응답도 받지 못하고 시간이 초과되는 것으로 알고 있습니다.

{[Error: socket hang up] code: 'ECONNRESET' }
Problem with request: undefined

Code:<BR>
const fs = require('fs');<BR>
const http = require('http');<BR>
const https = require('https');<BR>
var options = {<BR>
    method: "GET",<BR>
    hostname: "ServerName.com",<BR>
    port: 8445,<BR>
    rejectUnauthorized: 'false',<BR>
    cert: fs.readFileSync('Certname.cer'),<BR>
    ca: [ fs.readFileSync('Certname.cer') ],<BR>
    checkServerIdentity: () => { return null; },<BR>
    path: '/finesse/api/User/TEST/Dialogs'<BR>
    Authorization:'Basic',<BR>
    cacheControl: 'no-cache',<BR>
    acceptEncoding: "gzip, deflate",<BR>
    username: user,<BR>
    password: passw,<BR>
    Connection: 'keep-alive'<BR>
};<BR>

var req = http.request(options, function(res){<BR>
    var responseBody ="";<BR>
    console.log(`server status: ${res.statusCode}`);<BR>
    console.log("Responcer Headers: %j" , res.headers);<BR>
    res.setEnconding("UTF-8");<BR>
    res.once("data", (chunk)=>{ <BR>
        console.log(chunk);<BR>
    });<BR>
    res.on('data', function(chunk) { <BR>
        console.log(`---chunk-- ${chunk.length}`);<BR>
        responseBody +=chunk;<BR>
    });<BR>
    res.on("end", function() {<BR>
        fs.writeFile("userDialog.html", responseBody, function (error) {<BR>
            if (error) throw error; <BR>
        });<BR>
    });<BR>
});<BR>
req.on("error", function(err) {<BR>
    console.error(err);<BR>
    console.log(`Problem with request: ${err.mesage}`)<BR>
});<BR>

다음을 통해 완료될 때 동일한 요청우편 집배원올바른 내용을 반환합니다. Postman의 요청 코드를 복사하여 시도해 보았지만 결과는 동일했습니다. Postman의 헤더에는 두 가지 옵션이 더 있습니다.

"User-Agent": "PostmanRuntime/7.13.0", "Postman-Token": ....

그게 필요한지 모르겠어요... 어떤 아이디어라도 있나요?

정말 감사합니다!

관련 정보