1
votes

I am working on a NodeACS app in which I have to send xml as request from Java HTTP client and to receive response after some manipulation. The Java HTTP Client is working fine so far but the issue is with Node JS file. The req.on('data'...) event is not firing in my case. Following is the code of my JS file:

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

In the above code after getting request the index function is called and printing the output for console.log(req.headers); but as mentioned above the script is not running after that. Please help me out What am I missing in this.

For testing I have installed cURL on my system and sending POST request to server using cURL request using following command:

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

1 Answers

0
votes

Can you confirm you aren't consuming the body prior to this? If the body has been consumed already by another middleware like body-parser you would need to restream the body via something like connect-restreamer. If it were consumed, the data event would not be emitted.

If that checks out, check to see if the "end" event is being emitted. Could be a sign of the content-length header being set to the wrong value.