我正在尝试使用以下脚本通过node.js向我的工作api发出https请求
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();
而我所得到的回应是
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'
}
我在浏览器上使用jQuery发出了这个请求,它起作用了
$.post({
url, data,
success: res => console.log(res),
});
我尝试使用头部X-SSL-PROTOCOL,但没有成功。由于它们是机密的,所以URL和数据已被隐藏,但在jQuery示例和node.js中它们是相同的。