【问题标题】:getaddrinfo ENOTFOUND www.google.com www.google.com:80getaddrinfo ENOTFOUND www.google.com www.google.com:80
【发布时间】:2018-08-24 15:06:51
【问题描述】:

我的问题是跟进 Do I need a paid plan for using recaptcha on firebase function?

我发现自己处于同样的情况:我需要使用带有 Google Recaptcha API 的 Firebase 云功能。尽管如此,我还是遇到了 getaddrinfo enotfound 错误。

这是我的代码:

exports.checkRecaptcha =  functions.https.onRequest((req, res) => {

  res.set('Access-Control-Allow-Origin', "*")
  res.set('Access-Control-Allow-Methods', 'GET, POST')

const request = require('request');
const got = require('got');
      var requestQuery = req.query; 
      var secret_key = '---------';

      if( requestQuery != undefined && requestQuery != '' && requestQuery != null && requestQuery.response != undefined && requestQuery.response != '' && requestQuery.response != null ){
          var response = requestQuery.response;   

              got('recaptcha.google.com/recaptcha/api/siteverify?secret='+ secret_key +'&response=' +response, { json: true }).then(response => {
                console.log(response);
                res.status(200).send("");
              }).catch(error => {
                console.log(error);
                res.status(500).send(error);
              });


      }else{
          res.send({"responseCode" : 1,"responseDesc" : "Failed captcha verification=> FOIRAGE"});
      }

});

根据 Doug Stevenson 的说法,reCAPTCHA 服务器 API 已被列入白名单,所以我应该可以使用我的云功能访问它,但我没有。

【问题讨论】:

  • 您是否尝试过使用格式正确的完整网址?例如:https://recaptcha.google.com/recaptcha/api/siteverify
  • 它修复了它,但我不太明白,因为我删除了“http”试图解决这个问题。
  • 您需要“https”,而不是“http”。 Google 服务只能通过安全的 http 运行。

标签: javascript firebase recaptcha


【解决方案1】:

在 Cloud Functions 中获取 URL 时,您应该使用指定端点方案的完整 URL。 Google 端点始终需要 HTTPS,这是 HTTP 的安全版本。

【讨论】:

    猜你喜欢
    • 2017-02-21
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 2022-06-23
    • 2014-12-10
    • 1970-01-01
    相关资源
    最近更新 更多