简体   繁体   English

Node.js / Express,无法获取req.query

[英]Node.js / Express, can't get req.query

I try to retrieve datas with request.query, but it does not work : 我尝试使用request.query检索数据,但是它不起作用:

app.get('/test/', aFunction);

curl localhost:3000/test/?username=hello&password=word curl本地主机:3000 / test /?username = hello&password = word

result : 结果:

console.log(request.query); // { username: 'hello' }

Why password is missing in request.query ? 为什么request.query中缺少密码? I try : 我尝试:

app.get('/test/:param', aFunction);

curl localhost:3000/test/yop?username=hello&password=word curl本地主机:3000 / test / yop?username = hello&password = word

Same thing, password is missing i only have username in request.query 同样,密码丢失了,我在request.query中只有用户名

Any idea ? 任何想法 ?

Thank you 谢谢

The problem is your call to curl. 问题是您打电话来卷曲。 When calling curl in your shell you need to either escape ampersands or put the whole url in quotes, otherwise your shell sees the ampersand and tries to background the process using the command line up to that ampersand. 在shell中调用curl时,您需要转义&符或将整个url括在引号中,否则shell会看到&符,并尝试使用命令行(直到该&符)将进程后台化。

Try this instead: curl "localhost:3000/test/?username=hello&password=word" 请尝试以下操作: curl "localhost:3000/test/?username=hello&password=word"

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

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