node.js - Nodejs 事件错误 Express

标签 node.js express

我有这个 express 代码。

var express = require('express');
var http = require("http");
var https = require("https");
var app = express();

var optionsSB = {
     host: 'domain.com',
     path: '/wp-content/themes/domain/includes/ajax/get_properties.php'
};

var optionsLV = {
    host: 'apiproperties.local',
    path: '/properties/storeSB',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    }
};

https.get(optionsSB, function (https_res) {
    var dataSB = "";
    https_res.on("data", function (chunkSB) {
       dataSB += chunkSB;
    });
    https_res.on("end", function () {
        http.request(optionsLV, function(http_res){
            var dataVL = "";
            http_res.on("data", function (chunkVL) {
                dataVL += chunkVL;
            });
            http_res.on("end", function () {
                console.log(dataVL);
            });
        });
    });
});

app.listen(3000, function () {});

我收到此错误

events.js:183
  throw er; // Unhandled 'error' event
  ^

Error: connect ECONNREFUSED 127.0.0.1:80
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)

我已经尝试了一些事情,但我不知道问题是什么,问候。 我遵循教程中的一些说明,一切正常,但我不明白该错误。

最佳答案

当您在使用 https.get() 设置请求时遇到错误,但您没有任何错误处理程序来捕获该错误时,它会像这样抛出。您可以提供错误处理程序:

https.get(...).on('error', function(err) {
    // error here
    console.log(err);
});

具体错误似乎是 ECONNREFUSED。可能是目的地不接受您的 https 连接,也可能是它不喜欢您传递选项的方式。由于您拥有的只是主机和路径,因此您也可以只使用 URL:

https.get("https://somedomain.com//wp-content/themes/domain/includes/ajax/get_properties.php", ...);

关于node.js - Nodejs 事件错误 Express,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48231373/

相关文章:

node.js - Windows Azure 上的 nowJS

node.js - 带有自定义 "company_id" header 的 GET 请求在本地有效,但 header 不存在于 GCP App Engine 中

javascript - 如何返回一个对象而不是数组?

javascript - 如何在 Electron 应用程序中打包 express 服务器?

node.js - 通过 http.request 发出 post 请求时 req.body 为空

javascript - node.js 中 setInterval() 的奇怪行为(仅限 Windows,适用于 Linux)

git - npm install,缺少node_modules文件夹

javascript - 检查商店是否营业。 MySQL Node.js 业务逻辑

javascript - 如何使用父帐户 token 验证 Twilio 调用

node.js - 使用 Mailchimp API