gavdotnet
gavdotnet

Reputation: 2224

Node.js ignores all querystring parameters except the first one

I can't persuade Node.js to see the second parameter from my 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 --debug ./router_rest.js

I have the following code in my "router_rest.js" file:

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:

/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?

Upvotes: 5

Views: 1258

Answers (1)

JasonSmith
JasonSmith

Reputation: 73752

Node is fine.

The first ampersand in your curl command is causing the shell to run curl in the background. Add quotes around the URL and it will work.

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

Upvotes: 12

Related Questions