php 构建curl请求

2018-03-01T17:54:00
function httpCurl($url, $type = 'GET', $param = array())
{
    $type = strtoupper($type);

    $ch = curl_init($url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    if(!empty($param) && $type == 'POST')
    {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
    }
    curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $type);
    $result = curl_exec($ch);
    //print_r($result);
    if ($ch != null) curl_close($ch);

    return $result;
}
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »