我想出瞭如何使用Curl來完成它。我自己的登錄名和密碼以及商家組當然都隱藏在這段代碼中。但是,如何做到這一點:我希望這可以幫助任何處於相同情況的人。
$cookie_jar = tempnam('/tmp','cookie');
// log in
$c = curl_init('https://dashboard.powerreviews.com/dashboard/login');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, false);
$page = curl_exec($c);
curl_close($c);
$post_fields = array("j_username" => "USERNAME", "j_password" => "PASSWORD", "command"=>"Login");
$post_data = http_build_query($post_fields);
$c = curl_init('https://dashboard.powerreviews.com/process_login');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $post_data);
$page = curl_exec($c);
curl_close($c);
// switch to Reviews Account
$c = curl_init('https://dashboard.powerreviews.com/programs/epc?accessMerchantGroup=xxxxx');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
$csv_file = curl_exec($c);
curl_close($c);
// download RA unsubscribes
$c = curl_init('https://dashboard.powerreviews.com/dashboard/unsubscribes.csv');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
$csv_file = curl_exec($c);
curl_close($c);
echo $csv_file;
你試過了什麼? – Axalix
還沒有。明天要嘗試窺探第一件事。 – danjfoley
嘗試「捲曲」,看到這裏的一些例子:http://stackoverflow.com/questions/3008817/login-to-remote-site-with-php-curl – Axalix