javascript - Node.js 忽略除第一个参数之外的所有查询字符串参数

标签 javascript node.js rest curl query-string

我无法说服 Node.js 从我的 URL 中看到第二个参数:

http://localhost:8888/cities?tag=123&date=2013-03-30T10:00:28.000%2B02:00

我使用以下命令启动 Node.js 服务器:

node --debug ./router_rest.js

我的“router_rest.js”文件中有以下代码:

require("http").createServer(function (req, res) {
  //  For PUT/POST methods, wait until the
  //  complete request body has been read.
  if (req.method==="POST" || req.method==="PUT") {
    var body = "";
    req.on("data", function(data){
      body += data;
    })

    req.on("end", function(){
      return routeCall(req, res, body);
    })

  } else {
    return routeCall(req, res, "");
  }
}).listen(8888);

我从命令行进行以下调用:

curl http://localhost:8888/cities?tag=123&date=2013-03-30T10:00:28.000%2B02:00

当我调试和检查“req”参数时(在上面的匿名函数中),url 属性显示为:

/cities?tag=123

我期望报告的 url 是:

/cities?tag=123&date=2013-03-30T10:00:28.000%2B02:00

即使我切换参数, Node 仍然只看到第一个。

为什么最后一个参数(即日期)被 chop 了?

最佳答案

Node 很好。

curl 命令中的第一个 & 符号导致 shell 在后台运行 curl。在 URL 周围添加引号,它将起作用。

curl "http://localhost:8888/cities?tag=123&date=2013-03-30T10:00:28.000%2B02:00"

关于javascript - Node.js 忽略除第一个参数之外的所有查询字符串参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17486849/

相关文章:

r - 从源安装 Shiny 服务器时找不到模块 '../package'

javascript - 带偏移量的 javascript 数组的 Node 缓冲区

javascript - 回调内变量的范围

使用xml而不是jaxb注释的Java webservice工具?

rest - ReSpec vs Bikeshed : How to document and publish a standard REST API interface to be implemented by a number of vendors?

javascript - 创建 JavaScript 日期对象

javascript - ng-model 对象到字符串

javascript - 将光标设置在 div 元素上?

c# - 使用 ITextSharp 将谷歌可视化区域图 svg 添加到 pdf

java - Spring Security主体转换