有些时候直接curl请求数据会被服务器拒绝,需要加上请求头模拟真人操作,上代码。
$headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:33.0) Gecko/20100101 Firefox/33.0';
foreach( $headers as $n => $v )
{ $headerArr[] = $n .':' . $v; }
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL, '/common/journalism');
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_HTTPHEADER , $headerArr );
$arr = curl_exec($ch);
curl_close($ch);
echo $arr;