提交带有reCAPTCHA元素的表单时,出现此错误:无法读取未定义的属性'g-recaptcha-response'
这是我接收reCAPTCHA的代码
app.post('/captcha', function(req, res) {
console.log("BRUH")
if(req.body['g-recaptcha-response'] === undefined || req.body['g-recaptcha-response'] === '' || req.body['g-recaptcha-response'] === null)
{
return res.json({"responseError" : "Please select captcha first"});
}
const secretKey = "6Lez4cEUAAAAAHxMs9ChAG9CfU4Piu23ql2PYV2t";
const verificationURL = "https://www.google.com/recaptcha/api/siteverify?secret=" + secretKey + "&response=" + req.body['g-recaptcha-response'] + "&remoteip=" + req.connection.remoteAddress;
request(verificationURL,function(error,response,body) {
body = JSON.parse(body);
if(body.success !== undefined && !body.success) {
return res.json({"responseError" : "Failed captcha verification"});
console.log("error");
}
res.json({"responseSuccess" : "Sucess"});
console.log("succes");
});
});