From nodejs i am trying to post data to another URL 127.0.0.1:3002 (in file poster.js), but when i try to access it on server at 127.0.0.1:3002 then posted data is not coming:
My poster.js looks like this:
var http = require('http');
function post() {
var options = {
host : '127.0.0.1',
port : 3002,
path : '/note/',
method : 'POST'
};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function(chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.write("<some>xml</some>");
req.end();
}
post();
and my server code in app.js is:
var express=require('express');
app=express();
app.post('/note',function(req,res){
console.log(req.params);
})
app.listen(3002);
console.log('sweety dolly')
my server console is showing:
sweety dolly
[]
req.params is showing [] that means it received nothing while sending i am sending xml
in two different command line i am firing two different processes like
node app
and then in next command line
node poster
What am i doing wrong????