PHP cURL

    private function http_curl($url,$type='get',$res='json',$arr=''){
	   $req = curl_init();
	   curl_setopt($req, CURLOPT_URL, $url);
	   curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
	   curl_setopt($req, CURLOPT_FOLLOWLOCATION, 1);
	   curl_setopt($req, CURLOPT_HEADER,'text/html; charset=UTF-8');
	   if ($type == 'post') {
	       curl_setopt($req,CURLOPT_POST,1);
	       curl_setopt($req,CURLOPT_POSTFIELDS,$arr);
	   }
	   $reqrst = curl_exec($req);
	   if($res == 'json'){
	       if (curl_errno($req) ){
	           return curl_error($req);
	       }
	       return json_decode($reqrst,true);
	   }
	   return $reqrst;
	}
posted @ 2016-09-09 09:50  乌祁班岚图  阅读(102)  评论(0编辑  收藏  举报