简体   繁体   中英

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

I try to retrieve datas with request.query, but it does not work :

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

curl localhost:3000/test/?username=hello&password=word

result :

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

Why password is missing in request.query ? I try :

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

curl localhost:3000/test/yop?username=hello&password=word

Same thing, password is missing i only have username in 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.

Try this instead: curl "localhost:3000/test/?username=hello&password=word"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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