NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
~~~ /** * curl发送htpp请求 * 可以发送https,http,get方式,post方式,post数据发送 */ function dataRequest($url, $https = false, $method = 'get', $data = null, $header = false) { //初始化curl $ch = curl_init($url); //字符串不直接输出,进行一个变量的存储 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //header表头 if ($header != false) { curl_setopt($ch, CURLOPT_HTTPHEADER, $header); } //https请求 if ($https === true) { //确保https请求能够请求成功 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } //post请求 if ($method == 'post') { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } //发送请求 $str = curl_exec($ch); $aStatus = curl_getinfo($ch); //关闭连接 curl_close($ch); if (intval($aStatus["http_code"]) == 200) { return json_decode($str); } else { return false; } } ~~~