我想用php curl登錄一個用戶名和密碼的網站。PHP捲曲返回不完整的數據
<?php
$url = 'http://XXXXX.com/login';
$ch = curl_init();
$formFields = array('username' => 'XXXX', 'password' => 'WAO', 'button' => 'Login');
$cookiefile = 'C:/wamp/www/tests/cookies.txt';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formFields);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
echo $response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
但我沒有得到完整的HTML $迴應。意思是如果在瀏覽器中,我在HTML中獲得1000行。捲曲我得到350行左右的html。
它在工作,但突然停止工作。
任何幫助?
我懷疑這是一個網絡連接相關的問題。 – Prasanth
爲了更清楚的理解,請用 替換回顯行$ response = curl_exec($ ch); echo'
'; –我在使用代理時遇到過幾次,代理會以http狀態200返回不完整的響應! – joshweir