gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 22:59:44 26 4
gpt4 key购买 nike

我无法说服 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com