简体   繁体   English

Node.js无法读取HTML POST请求

[英]Node.js not reading HTML POST request

My node.js script is receiving HTML POST request calls from the google Chrome extension Postman but it's not seeing the key-value pairs. 我的node.js脚本正在从Google Chrome扩展程序Postman接收HTML POST请求调用,但是没有看到键值对。 Keeps giving me 一直给我

TypeError: Cannot read property 'username' of undefined
   at app.get.params.QueueUrl (/home/ec2-user/Outfitr/Server/index.js:45:53)
    at Layer.handle [as handle_request] (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/layer.js:82:5)
    at next (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/route.js:110:13)
    at Route.dispatch (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/route.js:91:3)
    at Layer.handle [as handle_request] (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/layer.js:82:5)
    at /home/ec2-user/Outfitr/Server/node_modules/express/lib/router/index.js:267:22
    at Function.proto.process_params (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/index.js:321:12)
    at next (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/index.js:261:10)
    at serveStatic (/home/ec2-user/Outfitr/Server/node_modules/express/node_modules/serve-static/index.js:59:14)
    at Layer.handle [as handle_request] (/home/ec2-user/Outfitr/Server/node_modules/express/lib/router/layer.js:82:5)

Here's my code. 这是我的代码。 Let me know if you need anything else 需要帮助请叫我

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);

Should be: 应该:

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

A good way to avoid this in the future is: 将来避免这种情况的好方法是:

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

And then just use the var username and var password in your code, much less error prone and a little more readable! 然后,只需在代码中使用var用户名和var密码,就可以减少出错的可能性,并增加可读性!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM