Curl PHP 验证码验证

问题描述 投票:0回答:1

我正在尝试使用 CURL 来验证验证码。

当我在 POSTMAN 中查询时,它起作用了。

当我使用 CURL 进行相同的查询时,我从 www.google.com/recaptcha/api/siteverify 得到“无效输入响应”。

我将查询从 x-www-form-upload 更改为默认值,并以转储 $_POST 变量的“localhost/f.php”为目标。 我的目的是看看收到了什么。

我注意到收到的“响应”字段被截断,这可以解释我的错误。 我正在寻找我需要做什么才能让整个字段长度通过。

    $jdata["secret"] = $recaptcha_secret_key;
    $jdata["response"] = $recaptcha_response;
    $jdata["remoteip"] = "111.111.111.111"; // Actual IP masked
    $json_params=json_encode($jdata, JSON_PRETTY_PRINT);
    print "<pre>$json_params</pre>\n";
    $ch = curl_init("localhost/f.php");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_SSLVERSION, 6);   // TLS 1.2
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/html"));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_params);
    $output = curl_exec($ch);

接收表格:

<h1>Form Vars</h1>
<?php
foreach ($_POST as $n => $v) { $s=strlen($n); print "Len=$s P=$n V=$v<br>\n"; }
?>
<h2>Done</h2>

输出:

Form Vars
S3=2070 P={ ____"secret":_"actualkeymasked", ____"response":_"03AFcWeA5vynnqRYr6oP-iela92Jjz2u4FHD79DtUNmEUo_h636eUecKPg_S3WSfF41TiebRgEoWE0epnGb2UAVgudxZ1dZhl8WC6uoNeRvPNaqsnqEHyUxovpNgbeEXJ3oPEpp6uMQV1W4L9x1t9jL1gpbErcFF8cwIy3NGQVfL6yCJ_qMFvqq4mPEStRzTccRMTlqrD9YQ6Hqe2IFH6TDhROzKSX4S3NRaxRBaqErBRcXMqN2y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3WDP_XhEymvGk6EOUsNlunUEt65SG_rFQrSEiKhQSehr8Sa4YLoEPLnIRBGxYfnfYOReXSXYvPTY0omhyENPeFNKj--sFgRrG1Bt20eLYZwwhOIh02uvhP9fXM3Rt2xLNGAMmcYbxNKmhlo4k8gaqofZXf-CLYfmZxxAefVg5wGzJDn67rXwcmSBG7P7ll8JXPime2t5OYCFpEStYmUjCggoVS-umyF1Bbxbi_qbDzz8nq6cSFizlR-5Ylsn2y3Xg_-2r4Ht2Qj3qGHlpC28wweH2k5zNmBF3CqENHcda1Mkua8YtrT7K_8XSKE-cv-zyksE7nIZyiehACsnyteSk_XuCLTX7bZNtIrOQLCfprYgD8lP_EXjkF3SQ8bdL9R-UsAeuwRvxi2IiLHZ8Uw_fnmyMjkt9HAmNz44lngzvJqFLXOGveIDSt2pETFxY_fwgHblqxi5doJMu6gP0KZd0q6xE45vYvoeTEKgYRa4u_uKmnpmLiyhWZFAcBCioc-M-J62gBG8milYLsUPzQ5aUB7AwwXpLxuNAhNBGbX5kntemU-PZBI7dGj257e60_mPv3WhZt7r-wynXsiKvr0TiiNzk80Wf3vVZlV4C4R9OnkLuoFiv8GkgK_4wXAA", ____"remoteip":_"actual ip masked" } V=
Done

我想知道为什么我收到的“响应”值被截断。

php curl
1个回答
0
投票

我设法让它发挥作用:

$jdata["secret"] = $recaptcha_secret;
$jdata["response"] = $recaptcha_response;
$jdata["remoteip"] = $ip;

$ch=curl_init("https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);   // TLS 1.2
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($jdata));
$output = curl_exec($ch);
© www.soinside.com 2019 - 2024. All rights reserved.