• PHP通用CURL类


    PHP通用CURL类,可POST/GET/文件传输

    function do_curl($url, $params = array(), $upload = false, $type = 'POST')
    {
        $method = strtoupper($type);
        if ($method == 'GET') {
            $url = "{$url}?" . http_build_query($params);
        }
        $ch = curl_init();
        // $header[] = "User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36";
        // //定义请求类型
        //       curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
        // 是否检测服务器的证书是否由正规浏览器认证过的授权CA颁发的
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // 是否检测服务器的域名与证书上的是否一致
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        // var_dump($params);die;
        if ($method == 'POST') {
            if ($upload) {        //设置上传文件
                $file = new CURLFile($upload['tmp_name'], $upload['type'], $upload['name']);
                $params[$upload['get_name']] = $file;
            }
            @curl_setopt($ch, CURLOPT_POST, 1);
            @curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        }
        $result = curl_exec($ch);
        curl_close($ch);
        if ($result === null || $result === false) {
            $this->error('操作出错!');
        } else {
            return $result;
        }
    }
  • 相关阅读:
    单例
    Label自适应高度
    通知中心(以夜间模式为例)
    ios VFL屏幕自适应
    网络请求数据(同步POST,异步POST)
    linux 设备文件
    linux 文件存取 软硬联接的区别
    linux 磁盘管理与文件系统
    linux开机过程
    Build Antlr4 projects with eclipse java project template.
  • 原文地址:https://www.cnblogs.com/bk233/p/9508024.html
Copyright © 2020-2023  润新知