标签:pos field php curl param header ssl func inf []
1 <?php 2 /** 3 * CURL HTTP.POST访问 4 * @param $url 5 * @param array $param 6 * @return mixed 7 */ 8 public function curl_post_http($url, $param = []) 9 { 10 $ch = curl_init();//初始化curl 11 curl_setopt($ch, CURLOPT_URL, $url); 12 curl_setopt($ch, CURLOPT_HEADER, 0); 13 curl_setopt($ch, CURLOPT_TIMEOUT, 30);// 设置超时 14 curl_setopt($ch, CURLOPT_POST, 1);// POST方式提交 15 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 16 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 17 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// 执行成功将结果返回,不自动输出任何内容 18 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));// POST 提交参数 19 $res = curl_exec($ch);//执行并获取HTML文档内容 20 curl_close($ch); //释放curl句柄 21 return $res;// 返回HTML文档 22 } 23 24 /** 25 * CURL HTTP.GET访问 26 * @param $url 27 * @param array $setopt 28 * @return mixed 29 */ 30 public function curl_get_http($url, $setopt = []) 31 { 32 $curl = curl_init(); // 初始化curl 33 curl_setopt($curl, CURLOPT_URL, $url); 34 curl_setopt($curl, CURLOPT_HEADER, 0); 35 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 36 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 37 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 38 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 39 curl_setopt($curl, CURLOPT_TIMEOUT, 30); //设置超 40 curl_setopt_array($curl, $setopt);//设置协议 41 $tmpInfo = curl_exec($curl); 42 //释放curl句柄 43 curl_close($curl); 44 return $tmpInfo; 45 }
标签:pos field php curl param header ssl func inf []
原文地址:https://www.cnblogs.com/fbio/p/9169062.html