【问题标题】:Is there a way to fix Recaptcha for ReactJS not working有没有办法修复 Recaptcha 导致 ReactJS 无法正常工作
【发布时间】:2022-08-06 08:24:26
【问题描述】:

我试图将验证码添加到我的反应应用程序中,并且前端按预期工作得很好。但是当后端调用 api 来验证验证码响应 (api) 我得到以下响应{ success: false, \'error-codes\': [ \'missing-input-secret\' ] }。 现在,当我记录请求以查看正在发送的数据时。我得到这个image。如您所见,正在发送秘密和响应,并且我的标头是正确的,但由于某种原因,我遇到了错误。

这是我的代码:

const captchaRequest = await axios.post(\'https://www.google.com/recaptcha/api/siteverify\', {
  secret: config.captchaSecretKey,
  response: captcha
}, {
  headers: {
    \'Content-Type\': \'application/json\',
  }
});

const captchaResponse = captchaRequest.data;

if (!captchaResponse.success) {
  return res.status(401).json({
    message: \'captcha failed\',
    success: false,
  });
}

如果有人可以请让我知道我做错了什么让我知道。

    标签: javascript node.js typescript axios captcha


    【解决方案1】:

    遇到同样的问题,您必须将数据作为参数而不是在正文中发送。

    const captchaResponse = await axios({ method: 'post', url: 'https://www.google.com/recaptcha/api/siteverify', params: { secret: '6LfBbkUhAAAAAMzpetr93z_6_3Cakf7ICJk7UBiK', response: captcha } });

    【讨论】:

      猜你喜欢
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多