我想弄清楚如何使用PHP和CURL登錄到網站https://login.alibaba.com。我正在使用下面的代碼,但它似乎並沒有工作。你會如何推薦我自動登錄到這個網站?以編程方式登錄AliBaba.com
我當前的代碼:
<?
$cookie = "cookie.txt";
// set global curl options
$curloptions = array(
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6',
CURLOPT_TIMEOUT => 60,
CURLOPT_COOKIEJAR => $cookie,
CURLOPT_COOKIEFILE => $cookie,
CURLOPT_REFERER => 'http://www.alibaba.com'
);
// set userinfo
$username = 'xxxxxxxxxxx';
$password = 'xxxxxxxxxxx';
// clear cookie.txt (fresh session)
$handle = fopen($cookie, 'w');
fclose($handle);
// make a dummy request to generate a session
curl_http_request('https://login.alibaba.com', $curloptions);
// login
curl_http_request('https://login.alibaba.com',
array(
CURLOPT_POSTFIELDS => 'xloginPassport=' . $username . '&xloginPassword=' . $password . '&noCsrfToken=&xloginCheckToken=&rememberme=&runatm=',
CURLOPT_POST => TRUE
), $curloptions
);
//example request
echo curl_http_request('https://login.alibaba.com',
array(
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE
), $curloptions
);
function curl_http_request ($url, $moreoptions = array(), $options = array())
{
foreach ($moreoptions as $k => $v) $options[$k] = $v;
$handle = curl_init($url);
curl_setopt_array($handle, $options);
ob_start();
$buffer = curl_exec($handle);
ob_end_clean();
curl_close($handle);
return $buffer;
}
?>
正統劇訪問或? – 2012-03-19 02:11:56
如果您有充分的理由以編程方式訪問它們,最好聯繫他們並詢問他們是否提供受支持的API訪問權限。比試圖繞開顯然是專門爲了阻止你想要做的事情而開發的保護更好... – 2012-03-19 03:54:06
你是否得到它的工作?即時尋找相同的 – 2012-11-28 12:57:29