我开始使用Node / Express并尝试了一些代码来理解POST请求。我有以下代码:
app.post('/:username', function(req, res)
{
if(req.isAuthenticated())
{
console.log("POST from autheticated users");
console.log(req.param("Operation"));
console.log(req.param("Value"));
}
else
{
console.log("POST from guest user");
console.log(req.param("Operation"));
console.log(req.param("Value"));
}
});
我使用Webstorms REST Client发送以下POST请求:
http:// localhost:8080 / user1?Operation = op1& Value = 1
我发送了几个不同的操作和值的POST请求,这是打印出来的:
POST from guest user
[ 'op1', 'op1' ]
[ '1', '1' ]
POST from guest user
[ 'op1', 'op1', 'op2' ]
[ '1', '1', '2' ]
POST from guest user
[ 'op1', 'op1', 'op2', 'op3' ]
[ '1', '1', '2', '3' ]
为什么跨参数保存POST参数?什么是获得当前参数的方法?如果这是POST中非常基本的概念,我很抱歉。