php curl post

WBOY
Release: 2016-06-23 13:24:26
Original
918 people have browsed it

 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 '<pre class="brush:php;toolbar:false">' . print_r($httpInfo, true) . '
Copy after login
';exit;38 }39 40 curl_close($ch); // 关闭cURL资源,并且释放系统资源41 42 43 44 return $result;45 }

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template