【问题标题】:Node JS HTTP Server request.on('data') event failureNode JS HTTP Server request.on('data') 事件失败
【发布时间】:2015-01-10 09:20:06
【问题描述】:

我正在开发一个 NodeACS 应用程序,我必须在其中发送 xml 作为来自 Java HTTP 客户端的请求,并在进行一些操作后接收响应。到目前为止,Java HTTP 客户端工作正常,但问题出在 Node JS 文件上。 req.on('data'...) 事件在我的情况下没有触发。 以下是我的 JS 文件的代码:

function index(req, res) {
    console.log(req.headers); //Its getting printed on console
    req.on('data', function (data) {
        console.log("Inside 1");     //Not printed on console
        ....REST OF THE CODE....
    });
    req.on('end', function () {
        res.writeHead(200);
        res.end();
    });
}

在上面的代码中,在获取请求后调用 index 函数并打印 console.log(req.headers); 的输出,但如上所述,此后脚本不再运行。请帮我看看我错过了什么。

为了测试,我在我的系统上安装了 cURL,并使用以下命令使用 cURL 请求向服务器发送 POST 请求:

curl -X POST -d @output.xml http://localhost:7788/

【问题讨论】:

    标签: javascript node.js express windows-7 titanium


    【解决方案1】:

    你能确认在此之前你没有吃过尸体吗?如果 body 已被另一个中间件(如 body-parser)消耗,则需要通过 connect-restreamer 之类的东西重新流式传输 body。如果被消费,则不会发出数据事件。

    如果检查成功,请检查是否正在发出“结束”事件。可能是 content-length 标头设置为错误值的标志。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      • 2016-06-27
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多