[英]Node.js ignores all querystring parameters except the first one
我不能說服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
我原以為報告的網址是:
/cities?tag=123&date=2013-03-30T10:00:28.000%2B02:00
即使我切換參數,節點仍然只能看到第一個。
為什么最后一個參數(即日期)被截斷了?
節點很好。
curl
命令中的第一個&符號導致shell在后台運行curl。 在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.