当我们的 Node 快速中间件使用请求库发出 HTTP POST 请求时, Node 应用程序会抛出此错误(错误仅存在于特定 Node 应用程序中,使用中间件的同一计算机上的其他应用程序中没有问题)。
当(通过中间件)向“http://outsite.com/requestData”发出外部 POST 请求时,POST 不起作用,并出现错误“Error: connect ENOENT/requestData”。
代码抛出错误:
var requestLib = require('request');
var url = "http://httpbin.org/post";
var reqOptions = {
uri: url,
method: "POST",
headers: {
"Content-Type": "application/text"
},
timeout: 100000,
body: encodeURIComponent("Testing"),
forever: true, //keepalive
};
requestLib(reqOptions, function(error, response, body) {
if (error) {
console.log(error);
}
});
最佳答案
我在多台机器上都遇到了这个问题。运行您提供的相同代码片段,我发现使用 request@2.69.0
时 POST 工作正常但始终失败 Error: ENOENT
对于 request@2.51.0
以及各种其他次要版本 < 2.69。
我建议使用以下内容更新您的 package.json 来解决此问题:
"request": "~2.69.0"
。
希望这会有所帮助 - 一段时间以来,我真的对应用程序之间不一致的行为感到摸不着头脑。
关于javascript - "Error: connect ENOENT"当 Node Express 中间件发出 POST 请求时(使用 Node 请求库),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35598422/