php curl


   /**
     * @param string $url
     * @param array $url_param
     * @param array $body_param
     * @param bool $is_post
     * @return mixed
     */

public
function sendHttpRequest($url,$url_param = null,$body_param = null,$is_post = true) { if($url_param){ $url_param = '?'.http_build_query($url_param); } if($body_param){ $body_param = json_encode($body_param); } $ch = curl_init($url.$url_param); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if($is_post){ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $body_param); } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $data = curl_exec($ch); curl_close($ch); return $data; }

 

posted @ 2018-12-15 17:36  飞翔的贺兰猪  阅读(122)  评论(0编辑  收藏  举报