JSB*_*ach 6 https post node.js
我有一个在 AWS 上的 Node 8.11.1 上运行的系统。有一个功能可以将日志写入另一台服务器。该函数接受它记录的请求对象。
我的问题是在实际的 POST 尝试期间出现的,出现以下错误:
错误:写入 EPROTO 139746875082624:错误:140770FC:SSL 例程:SSL23_GET_SERVER_HELLO:未知协议:../deps/openssl/openssl/ssl/s23_clnt.c:827:
我看不出我的代码有什么问题。
为什么会出现错误?我可以采取什么措施来修复它?
这是函数内部的代码:
const https = require('https');
try
{
const postData = "New log finished " + JSON.stringify(request, null, 2);
const options =
{
hostname: LOG_DOMAIN,
port: LOG_PORT,
path: '/',
method: 'POST'
};
const req = https.request(options);
req.on('error', (e) =>
{
console.error("ERROR writing logs: " + e);
});
req.write(postData);
req.end();
}
catch (e)
{
console.log(e);
}
Run Code Online (Sandbox Code Playgroud)
LOG_DOMAIN 和 LOG_PORT 是传递给函数的变量。
经过进一步研究,Aravind Voggu(见评论)的想法似乎是正确的:错误来自于尝试在只允许 HTTP 的服务器上使用 HTTPS。
当尝试保护与不安全的内容的连接时,OpenSSL 会终止。
使我的代码正常工作所需的唯一更改是从所使用的位置中的“https”中删除“s”。
const http = require("http");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9805 次 |
| 最近记录: |