1
我使用cUrl POST到網頁(不是本地),然後返回HTML。PHP /捲曲 - 循環和POST緩衝區不清除
我需要多次這樣做,所以cUrl代碼在while循環中。這是奇怪的事情:它第一次按預期的方式工作,但似乎沒有在每次後都清除POST緩衝區。 (我做close_curl($ ch),並且通過POST傳遞的所有數據都是正確的。)
例如,其中一個文本字段應該(並且是第一次)傳遞「ANY」。但第二次是通過「任何,任何」。
我是否正確,這個問題在於未清理的POST緩衝區?我該如何解決它?
SORRY:這裏是代碼的一個縮短版...
$someResults = mysql_query($someSQL);
while($record = mysql_fetch_array($alertResults)){
$url = "http://something.com/searchResults.asp";
$someV = "Hi";
$fields = array(
//date to post.
);
foreach($fields as $key=>$value){
$fields_string .= $key .'='. $value . '&';
}
rtrim($fields_string,'&');
$ch = curl_init();
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
curl_setopt($ch,CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
ob_start();
$html = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$resultTable = $xpath->evaluate("/html/body//table");
}
而且,我這樣做的時候,第一時間通過循環$ resultTable中有60項。但每次之後(使用相同的url)它有0個項目。而且我非常肯定這是因爲POST緩衝區沒有被清除,並且事情會發布到以前的POST數據的頂部。
如何每次通過循環清除POST數據?
你能發佈環/捲曲的代碼? – Oli 2010-12-23 10:29:34