Node.js 未阅读 HTML POST 请求

Node.js not reading HTML POST request

我的 node.js 脚本正在接收来自 google Chrome 扩展 Postman 的 HTML POST 请求调用,但它没有看到键值对。一直给我

类型错误:无法读取未定义的 属性 'username'
   在 app.get.params.QueueUrl (/home/ec2-user/Outfitr/Server/index.js:45:53)
    在 Layer.handle [作为 handle_request] (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/layer.js:82:5)
    接下来 (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/route.js:110:13)
    在 Route.dispatch (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/route.js:91:3)
    在 Layer.handle [作为 handle_request] (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/layer.js:82:5)
    在 /home/ec2-user/Outfitr/Server/node_modules/express/lib/router/index.js:267:22
    在 Function.proto.process_params (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/index.js:321:12)
    接下来 (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/index.js:261:10)
    在 serveStatic (/home/ec2-user/Outfitr/Server/node_modules/express/node_modules/serve-static/index.js:59:14)
    在 Layer.handle [作为 handle_request] (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/layer.js:82:5)

这是我的代码。如果您还需要什么,请告诉我

app.post('/bscreateuser', function(request, response) {
  process.stdout.write("Attempted to create a --- BBBSSSSS ---- user  |  ");
  process.stdout.write("request is " + request.url);
  process.stdout.write("username is " + request.body.username);
  process.stdout.write("Password is " + request.body.password);
  bscreateUser(request.query.username, request.body.password);
  response.send('Success' );
});

function bscreateUser(username, password) {
  messageBody = 'create_user("' + username + '","' + password + '")';
  queueUrl = DAO_QUEUE_URL;
  // sys.puts("--- going for BS ---");
  sendSQSMessage(JSON.stringify(messageBody), queueUrl);
}
 bscreateUser(request.query.username, request.body.password);

应该是:

 bscreateUser(request.body.username, request.body.password);

将来避免这种情况的一个好方法是:

var body = request.body;
var username = body.username;
var password = body.password

然后只需在您的代码中使用 var 用户名和 var 密码,更不容易出错并且更具可读性!