简体   繁体   English

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

[英]Node.js ignores all querystring parameters except the first one

I can't persuade Node.js to see the second parameter from my URL: 我不能说服Node.js看到我的URL中的第二个参数:

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

I start the Node.js server with the following command: 我使用以下命令启动Node.js服务器:

node --debug ./router_rest.js

I have the following code in my "router_rest.js" file: 我的“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);

I make the following call from the command line: 我从命令行进行以下调用:

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

When I debug and examine the 'req' parameter (in the anonymous function above), the url property appears as: 当我调试并检查'req'参数时(在上面的匿名函数中),url属性显示为:

/cities?tag=123

I was expecting the url reported to be: 我原以为报告的网址是:

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

Even when I switch parameters, node still only sees the first one. 即使我切换参数,节点仍然只能看到第一个。

Why has the last parameter (ie. date) been truncated? 为什么最后一个参数(即日期)被截断了?

Node is fine. 节点很好。

The first ampersand in your curl command is causing the shell to run curl in the background. curl命令中的第一个&符号导致shell在后台运行curl。 Add quotes around the URL and it will work. 在URL周围添加引号,它将起作用。

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

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

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