【问题标题】:recaptcha makes calls over http rather than httpsrecaptcha 通过 http 而不是 https 进行调用
【发布时间】:2012-08-22 16:08:33
【问题描述】:

我在我的 java jsp 设置中使用了 recaptcha。我在我的 jsp 中使用以下代码

<%@ page import="net.tanesha.recaptcha.ReCaptcha"%>
<%@ page import="net.tanesha.recaptcha.ReCaptchaFactory"%>


<%
ReCaptcha c = ReCaptchaFactory.newReCaptcha("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXX", false);
out.print(c.createRecaptchaHtml(null, null));
out.flush();
%>

但是该网站使用 https,所以我在 IE 上收到“仅显示安全内容”消息。

如果我查看源 recaptcha 已生成以下内容

<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=XXXXXXXXXXXXXXXXXXXXXXX"></script>

如何强制 recaptcha 使用 https 而不是 http?

【问题讨论】:

    标签: java jsp https recaptcha


    【解决方案1】:

    source code,需要改一下:

    ReCaptchaFactory.newReCaptcha(  //...
    

    与:

    ReCaptchaFactory.newSecureReCaptcha(  //...
    

    就是这样!

    另见

    【讨论】:

    • 谢谢。这将http更改为https。它仍然可以在本地运行,但是当我在我的 ssl 站点上托管它时,它无法从谷歌加载资源。我收到 document.write('Input error: Invalid referer');知道为什么吗?
    • @user456147:对不起,不是真的。我不知道你正在使用的图书馆。考虑问另一个问题?
    • 没有问题。原来我需要申请一个新的私钥和公钥。干杯。
    • 注意:Google 更改了他们的地址,您需要使用 0.0.8 的 jar,可以在此处找到 repo2.maven.org/maven2/com/google/code/maven-play-plugin/net/…,而不是从 Google 自己的文档链接到的 0.0.7 版本。
    【解决方案2】:

    您可以通过这种方式使其适用于安全和不安全的内容

    ReCaptcha c=null;
    
    if(request.getScheme().equals("https"))
    {
    
         c= ReCaptchaFactory.newSecureReCaptcha(
                Constants.RECATCHA_PUBLIC_KEY,
                Constants.RECATCHA_PRIVATE_KEY, false);
    }else{
    
         c = ReCaptchaFactory.newReCaptcha(
                Constants.RECATCHA_PUBLIC_KEY,
                Constants.RECATCHA_PRIVATE_KEY, false);
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-01
      • 2012-11-16
      • 2019-11-21
      • 1970-01-01
      • 2014-08-06
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      相关资源
      最近更新 更多