1 /** 2 * @desc curl post请求 3 * @date 2015-08-19 10:03:47 4 * @name cloudshadow 5 * 6 * @param $url 请求的url 7 * @param $post 请求的数据 8 * 9 * @return bool|mixed10 */11 private function curlpost($url, $post, $header = )12 {13 $ch = curl_init($url);14 curl_setopt($ch, curlopt_ssl_verifypeer, false);15 curl_setopt($ch, curlopt_ssl_verifyhost, false);16 curl_setopt($ch, curlopt_returntransfer, true); // 将curl_exec()获取的信息以文件流的形式返回,而不是直接输出。17 curl_setopt($ch, curlopt_header, $header); // 设置请求头部header数据18 curl_setopt_array($ch, array(19 curlopt_timeout => 30, //设置curl允许执行的最长秒数 30s20 curlopt_connecttimeout => 1, // 在发起连接前等待的时间,如果设置为0,则无限等待。21 curlopt_post => true, // 是否使用post方式请求 true 是22 curlopt_postfields => http_build_query($post), // post 请求数据23 ));24 25 //抓取url并把它传递给浏览器26 $result = curl_exec($ch);27 28 //获取执行后的 http 状态码29 $httpcode = curl_getinfo($ch, curlinfo_http_code);30 if ($httpcode != 200) { // 非200说明异常31 $result = false;32 }33 34 // 获取执行后的 http 头部header35 if (isset($_get['debug'])) {36 $httpinfo = curl_getinfo($ch);37 echo '' . print_r($httpinfo, true) . '
';exit;38 }39 40 curl_close($ch); // 关闭curl资源,并且释放系统资源41 42 43 44 return $result;45 }