/* * 发送采集请求的方法 */ private function http_curl($url,$type='get',$res='json',$data=''){ //1.创建连接资源 $ch = curl_init(); //2.设置参数 curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); if($type=='post'){ curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$data); } //3.采集 $output = curl_exec($ch); //4.关闭 curl_close($ch); if($res='json'){ if(curl_errno($ch)){ return curl_errno($ch); } return json_decode($output,true); } } |
|