PHP CURL
Posted 公主的咖啡屋
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP CURL相关的知识,希望对你有一定的参考价值。
public function http_get($url){ $ch = curl_init(); //设置超时 curl_setopt($ch, CURLOP_TIMEOUT, 5); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $res = curl_exec($ch); curl_close($ch); return $res; } public function http_post($url,$param){ $oCurl = curl_init(); if(stripos($url,"https://")!==FALSE){ curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($oCurl, CURLOPT_URL, $url); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true ); curl_setopt($oCurl, CURLOPT_TIMEOUT, 5);//允许执行的最长秒数 curl_setopt($oCurl, CURLOPT_POST,true); curl_setopt($oCurl, CURLOPT_POSTFIELDS,$param); curl_setopt($oCurl, CURLOPT_HTTPHEADER, array( ‘Content-Type: application/json‘, ‘Content-Length: ‘ . strlen($param)) ); $sContent = curl_exec($oCurl); $aStatus = curl_getinfo($oCurl); curl_close($oCurl); if(intval($aStatus["http_code"])==200){ return $sContent; }else{ return false; } }
以上是关于PHP CURL的主要内容,如果未能解决你的问题,请参考以下文章
转:PHP中的使用curl发送请求(GET请求和POST请求)
CentOS yum 命令出现 [Errno 14] curl#6 - "Couldn't resolve host ..." 的解决方法(代码片段