The script that I am using is:
var http = require('http');
var options = {
host: 'some url',
port: 80,
path: 'path',
method: 'POST'
};
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write('username=abcd&password=defg');
req.end();
I am getting a response as 404 bad request by server.. but when I use the firefox add-on "poster" for posting the same parameters to the server.. I am getting a proper reply, i.e 200 status code.. I think this the problem with the string I am passing in req.write()
. but the same string is working fine with poster.. Can someone explain what the issue is?