I do 现场验证 https://developers.google.com/recaptcha/docs/verify得到后g-recaptcha-response
通过用户验证。
我发送带有参数的 xhr POST 并得到 200 OK,但没有响应,因为它应该是:
{
"success": true|false,
"error-codes": [...] // optional
}
Code
<script type='text/javascript'>
var onReturnCallback = function(response) {
document.getElementById('resp').innerHTML = response; // works well
//alert('grecaptcha.getResponse() = ' + grecaptcha.getResponse()); // works well too
$.post("https://www.google.com/recaptcha/api/siteverify",
{ secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
response: response,
remoteip : "<?php echo $ip;?>" // optional, does not influence an empty result
}).complete(function( data ) {
alert( "Data returned from POST: " + data.toString() );
console.dir(data);
});
};
</script>
Form.
<form method="post">
<div class="g-recaptcha" data-sitekey="6LdYKQkTAAAAAD9K6-kHspFUPUnftw1RxP5_awi0" data-callback="onReturnCallback" data-theme="light"> </div>
<input name="send" type="submit" />
</form>
我在控制台中打印的对象完全是空的(除了statusText='error'
),参见shot http://joxi.ru/MAjRad1hJpY8Ae.
控制台中还有其他错误:
XMLHttpRequest 无法加载https://www.google.com/recaptcha/api/siteverify https://www.google.com/recaptcha/api/siteverify。请求的资源上不存在“Access-Control-Allow-Origin”标头。起源 'http://tarex.ru http://tarex.ru' 因此不允许访问。
怎么处理呢?我可以更改原始标头吗?如何验证?
The link http://tarex.ru/testdir/recaptcha/form.php到演示。
由于所谓的“同源策略”(SOP) 来防止 XSS 攻击,因此无法向服务网站的主机以外的主机发出 XHR(“AJAX 请求”)。
但是,您可以从在您自己的主机上运行的 php 代理发布到 reCaptcha 站点。给出了一个例子在这个答案中 https://stackoverflow.com/a/23608173/4014509。这也可以防止您的秘密向查看您的客户端源代码的人公开。
另一种可能性(取决于您要使用的服务)是JSONP https://en.wikipedia.org/wiki/JSONP。由于 XHR 是被禁止的,但从外部主机加载脚本却不是,因此可以通过查询参数将回调函数的名称添加到脚本 URL。一旦外部资源被加载,这个函数就会被调用。但据我所知 reCaptcha 不支持 JSONP。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)