Javascript Node.js http服务器

Javascript Node.js http服务器,javascript,node.js,Javascript,Node.js,我正在尝试创建一个http服务器,它只读取POST请求并以大写形式返回请求体。这是我的代码: 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

我正在尝试创建一个http服务器,它只读取POST请求并以大写形式返回请求体。这是我的代码:

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]);
试试这个答案: