码迷,mamicode.com
首页 > Web开发 > 详细

curl的POST请求,封装方法

时间:2018-10-30 17:34:41      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:选项   top   error   封装   参数   orb   head   return   result   

//POST请求
//参数1是请求的url
//参数2是发送的数据的数组
//参数3是其他POST选项
public static function POST($url, array $post = array(), array $options = array(), $timeout = 10)
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_POSTFIELDS => http_build_query($post),
CURLOPT_SSLVERSION => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 2
);

$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));

$result = curl_exec($ch);
if ($result === false)
{
Yii::log("POST ERROR:" . curl_error($ch));
}

curl_close($ch);

return $result;
}

curl的POST请求,封装方法

标签:选项   top   error   封装   参数   orb   head   return   result   

原文地址:https://www.cnblogs.com/gramblog/p/9876889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!