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?
The order of parameters matters in query strings. In the following example, the query strings are identical except that the parameters are in a different order.
The querystring. encode() function is an alias for querystring. stringify() .
To pass in parameter values, simply append them to the query string at the end of the base URL. In the above example, the view parameter script name is viewParameter1.
delete() The delete() method of the URLSearchParams interface deletes the given search parameter and all its associated values, from the list of all search parameters.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With