function getAction($url='')
{ // curl 请求一共分四步,初始化,设置属性,执行并获取结果,释放句柄 // 一、初始化 $curl = curl_init();// 二、设置属性
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 跳过证书验证(https)的网站无法跳过,会报错 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书验证curl_setopt($curl, CURLOPT_URL, $url); // 设置curl请求的地址
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 返回的数据不打印// 三、发送请求,并接收数据
$data = curl_exec($curl);// 四、释放句柄
curl_close($curl); return $data; // 未对数据 json_decode()}// post请求
function postAction($url='', $data=array()){ $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $result = curl_exec($curl); curl_close($curl); return $result;} posted on 2016-11-20 10:41 阅读( ...) 评论( ...)