首页 > 代码库 > curl的应用

curl的应用

curl应用的post场景

        $ch = curl_init(); //初始化curl
        curl_setopt($ch, CURLOPT_URL, $postUrl); //抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//采集https,设置
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = http://www.mamicode.com/curl_exec($ch); //运行curl
        curl_close($ch);

curl应用的get场景

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//采集https,设置
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $data = http://www.mamicode.com/curl_exec($ch);
        curl_close($ch);

curl的应用