【问题标题】:Recaptcha Validation : IOException : Tried all: 1 addresses, but could not connect over HTTPS to server: google.com port: 443Recaptcha 验证:IOException:尝试了所有:1 个地址,但无法通过 HTTPS 连接到服务器:google.com 端口:443
【发布时间】:2017-11-06 20:55:30
【问题描述】:

我已将 Recaptcha V2 集成到联系表单中。对于服务器端验证,我使用以下代码:

private JsonObject validateCaptcha(String secret, String response, String remoteip)
  {
      JsonObject jsonObject = null;
      URLConnection connection = null;
      InputStream is = null;
      String charset = Charset.forName("UTF-8").name();
      String url = "https://google.com/recaptcha/api/siteverify";
      try {            
          String query = String.format("secret=%s&response=%s&remoteip=%s", 
          URLEncoder.encode(secret, charset),
          URLEncoder.encode(response, charset),
          URLEncoder.encode(remoteip, charset));

          connection = new URL(url + "?" + query).openConnection();
          is = connection.getInputStream();
          JsonReader rdr = Json.createReader(is);
          jsonObject = rdr.readObject();
      } catch (IOException ex) {
          System.out.println("IOException= "+ex.getMessage());
      }
      finally {
          if (is != null) {
              try {
                  is.close();
              } catch (IOException e) {
                  //cannot do anything here
              }
          }
      }
      return jsonObject;
  }

它抛出一个 IOException 并在第一个 catch 块中被捕获: 尝试了所有:1 个地址,但无法通过 HTTPS 连接到服务器:google.com 端口:443

我尝试将链接更改为: https://wwww.google.com/recaptcha/api/siteverify 但同样的错误。 我从 localhost 运行,并在 Recaptcha 管理控制台中成功添加了“127.0.0.1”作为域。

这个问题可能是什么原因。我知道我们的应用程序位于防火墙后面。

【问题讨论】:

    标签: java https recaptcha


    【解决方案1】:

    我没有在代码中看到 ant 错误。只需与网络团队核实,如果端口 443 可用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-03
      • 2013-12-22
      • 1970-01-01
      • 2013-11-11
      • 1970-01-01
      • 2021-11-26
      • 2016-11-19
      相关资源
      最近更新 更多