【问题标题】:retrieving multiple query string parameters Express 4检索多个查询字符串参数 Express 4
【发布时间】:2015-09-07 21:58:05
【问题描述】:
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var url = require('url');

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));

// parse application/json
app.use(bodyParser.json())
app.get('/', function (req, res) {
  console.log(req.query); 
  res.send('Hello World');
})

app.listen(3000);


curl http://localhost:3000/?a=1&b=3

控制台日志返回 { a: '1' }。

我错过了什么吗?

【问题讨论】:

  • 代码对我来说看起来不错。我希望 req.query.b 在您的路由处理程序中具有值 3

标签: node.js express query-string


【解决方案1】:

& 是一个 shell 命令,它使您的进程成为后台,因此 & 之后的所有内容都不会传递给 curl。

您需要使用curl 'http://localhost:3000/?a=1&b=3'(注意引号)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    相关资源
    最近更新 更多