卷曲程序得到验证码

时间:2018-11-03 20:13:42

标签: php curl

我正在向没有通过网页浏览器访问验证码的网站发出卷曲请求,但是由于某种原因,使用CURL访问时会有一个验证码。如何做到这一点,使我得到的响应就好像我在使用不会显示capatcha的浏览器一样?这主要是关于学习如何像浏览器访问Web内容一样有效地使用CURL。这是我的CURL代码:

    $url = "example.com";
    $var = "Var";
    $var1 = "Var1";
    $var2 = "Var2";
    $var3 = "Var3";
    $var4 = "Var4";


$fields = array(
                        'var' => urlencode($var),
                        'var1' => urlencode($var1),
                        'var2' => urlencode($var2),
                        'var3' => urlencode($var3),
                        'var4' => urlencode($var4)
                );

//url-ify the data for the POST
$fields_string = "";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

//execute post
$result = curl_exec($ch);
if (curl_error($ch)) {
    $error_msg = curl_error($ch);
}
//close connection
curl_close($ch);

if (isset($error_msg)) {
    echo "Curl Error: '$error_msg'<br>";
}

echo "Result: $result<br>";
exit("exiting at 49");

谢谢。

0 个答案:

没有答案