使用不同的POST数据创建cURL

时间:2015-03-02 09:05:41

标签: php curl

我创建了一个代码算法,可以创建10个不同的数字。通过使用PHP cURL,我想将POST请求发送到具有不同10个数字的网站,然后获取它们的响应主体。这是我生成10个不同数字的示例代码:

function solver($aaa,$bbb,$number) {  
    $solo = substr($aaa,0,9);  
    $x=substr($solo,0,5);  
    $y=substr($solo,5,4);  

    if ($bbb == 0) { 
        for ($i = 1; $i <= $number ; $i++ ) { 
            $xx=$x+8*$i;
            $dokuz=$xx.$y-1*$i;

            $yeni=$dokuz;  
            echo $yeni."<br>"; 
        } 
    } 
} 

solver("12345678912",0,10);  

这是cURL:

<?
$url = "http:/example.com/solver.aspx";
$postdata = 'number'.'='.$yeni;
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);

preg_match_all("/id=\"__VIEWSTATE\" value=\"(.*?)\"/", $result, $arr_viewstate);
$viewstate = urlencode($arr_viewstate[1][0]);

preg_match_all("/id=\"__EVENTVALIDATION\" value=\"(.*?)\"/", $result, $arr_validation);
$eventvalidation = urlencode($arr_validation[1][0]);

preg_match_all("/id=\"__LASTFOCUS\" value=\"(.*?)\"/", $result, $arr_lastfocus);
$lastfocus = urlencode($arr_lastfocus[1][0]);

preg_match_all("/id=\"__EVENTTARGET\" value=\"(.*?)\"/", $result, $arr_eventtarget);
$eventtarget = urlencode($arr_eventtarget[1][0]);

preg_match_all("/id=\"__EVENTARGUMENT\" value=\"(.*?)\"/", $result, $arr_eventargument);
$eventargument = urlencode($arr_eventargument[1][0]);

$options = array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => "",
    CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0",
    CURLOPT_AUTOREFERER => true,
    CURLOPT_CONNECTTIMEOUT => 120,
    CURLOPT_TIMEOUT => 120,
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => '__EVENTTARGET='.$eventtarget.'&__EVENTARGUMENT='.$eventargument.'&__VIEWSTATE='.$viewstate.'&__EVENTVALIDATION='.$eventvalidation.'&__LASTFOCUS='.$lastfocus.'&'.$postdata.'&Submit=submit');    
    $ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$result = curl_exec ($ch);

preg_match("/<input name=\"Adi\" type=\"text\" value=\"(.*?)\" maxlength=\"25\" id=\"txtAdi\" disabled=\"disabled\" class=\"aspNetDisabled\" \/>/", $result, $adi);
$cikan = "<b>".$yeni."</b>"."&nbsp;"."&nbsp;".$adi[1]."&nbsp;";
print($cikan);
curl_close ($ch);

所以,我试图用这10个不同的数字做10次cURL回复。任何人都可以帮我解决这个问题吗?

谢谢,

0 个答案:

没有答案