我正在尝试使用“req.query.code”从 url 正文中获取代码,但是它是空的,并且 url 完美地显示了代码,我不知道会发生什么,这是我的 server.js 文件:
app.get('/validate', async (req, res, next) => {
if (!req.query.code || req.query.code != "") {
console.log(clc.red(`Error: No code provided`));
res.send(`Error: The code is missing, please check the documentation`);
return;
}
else {
console.log(req.query.code);
}
}
当我看到错误时,网址有代码。
http://xxxxxxxx:3001/validate?code=xxxxxxxxxxa64779xxxxxe42fe16xx8063xxxx2xxxx
您的 if 条件或第二个条件中的运算符有问题您正在检查非空 req.query.code 因为 if 块正在执行尝试这个
if (!req.query.code || req.query.code === "")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句