海滨擎蟹

php 构建curl请求

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;
}

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »