简体   繁体   English

尝试使用 https 模块进行 POST 时,Node.js v8.11.1 EPROTO 错误

[英]Node.js v8.11.1 EPROTO error when attempting to POST using https module

I have a system that is running on Node 8.11.1 on AWS.我有一个在 AWS 上的 Node 8.11.1 上运行的系统。 There is a function that writes logs to another server.有一个将日志写入另一台服务器的功能。 This function takes a request object that it logs.此函数采用它记录的请求对象。

My problem arises during the actual POST attempt, giving me the following error:我的问题在实际 POST 尝试期间出现,给我以下错误:

Error: write EPROTO 139746875082624:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:827:错误:写入 EPROTO 139746875082624:错误:140770FC:SSL 例程:SSL23_GET_SERVER_HELLO:未知协议:../deps/openssl/openssl/ssl/s23_clnt.c:827:

I cannot see anything wrong with my code.我看不出我的代码有什么问题。
Why is the error occurring, and what can I do to fix it?为什么会发生错误,我该怎么做才能修复它?

Here is the code inside of the function:这是函数内部的代码:

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);
}

LOG_DOMAIN and LOG_PORT are variables passed to the function. LOG_DOMAIN 和 LOG_PORT 是传递给函数的变量。

After further research, it appears that Aravind Voggu (see comments) was in the right vein: the error comes from attempts to use HTTPS for a server that only allows HTTP. 经过进一步的研究,看来Aravind Voggu(请参阅注释)是正确的:错误来自尝试将HTTPS用于仅允许HTTP的服务器。

The OpenSSL dies when attempting to secure a connection to something that is unsecured. 尝试保护到不安全对象的连接时,OpenSSL会死掉。

The only change required to make my code work correctly was to remove the "s" from "https" in the locations used. 使我的代码正常工作所需的唯一更改是从使用的位置中的“ https”中删除“ s”。

const http = require("http");

如果服务器端 ssl 证书过期,可能会遇到此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM