我从我的网站调用外部服务 API 来获取数据。最近,我所做的每次调用都会返回一个 CloudFlare 页面,该页面阻止我获得我想要的结果。
该网站的所有者告诉我,可能我收到该页面的请求太多,我只需要在该页面中填写验证码的表格即可。
现在的问题是:如何从我的网站自动填写表格?我只能看到带有简单
file_get_contents
的响应页面,但我无法使用浏览器填写验证码,因为不是我的IP被阻止了。
这是
file_get_contents
的结果:
我该如何解决这个问题?我有一个共享主机。
如果网站所有者同意您向网站发出请求,您实际上可以要求网站所有者将发出呼叫的 IP 列入白名单。网站所有者可能会通过请求触发 Web 应用程序防火墙,但他们可以通过将您的 IP 列入白名单来覆盖该行为。
这是不可能的,因为 Cloudflare 不会返回 API 密钥,因此用户可以使用获得的令牌进行验证。
可以通过在 CloudFlare 外部创建 Google reCAPTCHA 项目来获取 API 密钥,这是我推荐的。
用户:
根据定义,您不能使用计算机来“执行”此操作 挑战的期限和性质。
GL
我使用以下代码在 CiviCRM 的表单保护扩展中添加了 Cloudflare Turnstile 验证码:
if (\Civi::settings()->get('formprotection_enable_cloudflare_captcha')) {
$enabledForms = \Civi::settings()->get('formprotection_recaptcha_enabled_quickforms');
if(is_array( $enabledForms) && count($enabledForms) > 0) {
if (in_array($formName, $enabledForms) || $enabledForms[0] == 'all') {
$public_key = \Civi::settings()->get('formprotection_cloudflare_captcha_publickey');
$secret_key = \Civi::settings()->get('formprotection_cloudflare_captcha_secretkey');
if($public_key == NULL || $public_key == '' || $secret_key == NULL || $secret_key == '') {
CRM_Core_Resources::singleton()->addScript("
CRM.$(document).ready(function($) {
$('<div class=cf-turnstile>Cloudflare captcha keys error.</div>').insertBefore('.entry-content form.{$formName} .crm-form-submit');
});
");
}
else {
CRM_Core_Resources::singleton()->addScriptUrl('https://challenges.cloudflare.com/turnstile/v0/api.js');
CRM_Core_Resources::singleton()->addScript("
CRM.$(document).ready(function($) {
$('<div class=cf-turnstile data-sitekey=\"{$public_key}\" data-callback=javascriptCallback></div>').insertBefore('.entry-content form.{$formName} .crm-form-submit');
});
");
}
}
}
}
这段代码被添加到生成表单 HTML 的位置。
如果你真的想成为一个坏男孩,请尝试谷歌搜索类似 DeathByCaptcha 的内容。