Node.js http服务器

我正在尝试创build一个仅读取POST请求的http服务器,并以大写forms返回请求的正文。 这是我的代码:

http=require("http"); fs=require("fs"); http.createServer(function(req,res){ if(req.method=="POST") { var body = ''; req.on('data', function (data) {body += data.toString();}); body=body.toUpperCase() res.end(body); } else { res.end("Not a POST request."); } }).listen(process.argv[2]); 

当我从命令提示符(指定一个端口号)运行这个时,我得到以下错误:

 Error connecting to http://localhost:61777: read ECONNRESET 

我如何得到这项工作?

你完成后,你必须发送的身体,以获得它。

 http.createServer(function(req,res){ if(req.method=="POST") { var body = ''; req.on('data', function (data) {body += data.toString();}); // Please see this line: req.on('end', function (data) { body=body.toUpperCase(); res.end(body);}); } else { res.end("Not a POST request."); } }).listen(process.argv[2]);