标签:public code array https content 执行 header stat 设置
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; } }
标签:public code array https content 执行 header stat 设置
原文地址:http://www.cnblogs.com/ding-daisy/p/6003310.html