I'm trying to make a https request to an api of my work using node.js through the following script
const https = require('https');
const options = {
hostname,
path: fullPath,
port: 80,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
console.log('statusCode:', res.statusCode);
res.on('data', chunk => console.log('chunk:', chunk));
});
req.on('error', error => {
console.log('Failed!');
console.log(error);
});
req.write(data);
req.end();
And as a response i get
Failed!
Error: write EPROTO 6772:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:
at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:87:16) {
errno: 'EPROTO',
code: 'EPROTO',
syscall: 'write'
}
I made this request on a browser using jQuery and it worked
$.post({
url, data,
success: res => console.log(res),
});
I tryed to use the header X-SSL-PROTOCOL with no success. The url and data are hidden because they are confidential, but they are the same in the jQuery example and in node.js.