他们可能会在首页加载时向您提供会话 cookie
尝试使用 CURLOPT_COOKIEJAR 发出请求,然后使用 CURLOPT_COOKIEFILE 和 CURLOPT_COOKIEJAR 发出登录请求
另外,这是我为了让请求看起来更干净而创建的一个函数
function curl_http_request ($url, $options)
{
$handle = curl_init($url);
curl_setopt_array($handle, $options);
ob_start();
$buffer = curl_exec($handle);
ob_end_clean();
curl_close($handle);
return $buffer;
}
使用示例
$options = array(
CURLOPT_RETURNTRANSFER => TRUE
);
curl_http_request($url, $options);
这应该有效
// 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.meetup.com/'
);
// set userinfo
$username = '[email protected] /cdn-cgi/l/email-protection';
$password = '[email protected] /cdn-cgi/l/email-protection';
$cookie = 'cookie.txt';
// clear cookie.txt (fresh session)
$handle = fopen($cookie, 'w');
fclose($handle);
// make a dummy request to generate a session
curl_http_request('http://www.meetup.com/login/', $curloptions);
// login
curl_http_request('http://www.meetup.com/login/',
array(
CURLOPT_POSTFIELDS => 'email=' . urlencode($username) . '&password=' . urlencode($password) . '&rememberme=on&submitButton=Login&returnUri=http%3A%2F%2Fwww.meetup.com%2F&op=login',
CURLOPT_POST => TRUE
), $curloptions
);
//example request
echo curl_http_request('http://www.meetup.com/account/',
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;
}
希望这个能起作用:)