Recaptcha Error: I/O Exception: Name in certificate does not match host name

Recaptcha Error: I/O Exception: Name in certificate does not match host name

所以我正在尝试让 ReCaptcha 在 ColdFusion 上工作(下面是完整的源代码)。我尝试同时使用 get/post,但我得到了同样的错误。

I/O Exception: Name in certificate `google.com' does not match host name `www.google.com'

我将我的代码转换为 PHP(下面是完整的源代码)并且它工作正常。唯一的区别是 PHP 代码仅使用 get 方法。

知道我可能做错了什么吗?感谢您的帮助。

Coldfusion代码:

<cfif StructKeyExists(Form, "submit")>
    <cfset googleurl = "https://www.google.com/recaptcha/api/siteverify" />
    <cfset recaptchasecret = "secret-key-here" />
    <cfset recaptcha = FORM["g-recaptcha-response"] >
    <cfset remoteip = CGI["remote_addr"] />

    <!---post method--->
    <!---<cfhttp url="#googleurl#" method="post" resolveURL="yes">
        <cfhttpparam type="formfield" name="secret" value="#recaptchasecret#" />
        <cfhttpparam type="formfield" name="response" value="#recaptcha]#" />
        <cfhttpparam type="formfield" name="remoteip" value="#remoteip#" />
    </cfhttp>--->

    <!---get method--->
    <cfhttp url="#googleurl#?secret=#recaptchasecret#&response=#recaptcha#&remoteip=#remoteip#" method=get/>

    <cfdump var="#cfhttp#"><hr>
    <cfabort>
</cfif>

<html>
    <head>
        <title>Google recapcha demo - Codeforgeek</title>
        <script src='https://www.google.com/recaptcha/api.js'></script>
    </head>
    <body>
        <h1>Google reCAPTHA Demo</h1>
        <form id="comment_form" action="test.cfm" method="post">
            <input type="email" placeholder="Type your email" size="40"><br><br>
            <textarea name="comment" rows="8" cols="39"></textarea><br><br>
            <input type="submit" name="submit" value="Post comment"><br><br>
            <div class="g-recaptcha" data-sitekey="site-key-here"></div>
        </form>
    </body>
</html>

PHP代码:

<?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        var_dump($_POST);

        $googleurl = "https://www.google.com/recaptcha/api/siteverify";
        $secretKey = "secret-key-here";
        $captcha=$_POST['g-recaptcha-response'];
        $ip = $_SERVER['REMOTE_ADDR'];

        $response=file_get_contents($googleurl."?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);

        $responseKeys = json_decode($response,true);

        var_dump($responseKeys);
    }
?>

<html>
    <head>
        <title>Google recapcha demo - Codeforgeek</title>
        <script src='https://www.google.com/recaptcha/api.js'></script>
    </head>
    <body>
        <h1>Google reCAPTHA Demo</h1>
        <form id="comment_form" action="test.php" method="post">
            <input type="email" placeholder="Type your email" size="40"><br><br>
            <textarea name="comment" rows="8" cols="39"></textarea><br><br>
            <input type="submit" name="submit" value="Post comment"><br><br>
            <div class="g-recaptcha" data-sitekey="site-key-here"></div>
        </form>
    </body>
</html>

这是一个 SSL 问题 - java 无法正确连接到 "www.google.com"。作为临时解决方法,请使用 <cfset googleurl = "https://google.com/recaptcha/api/siteverify" />。但一定要更新 java 的证书库。