src/Client/Http.php
public static function send($rq)
    {
        if (self::$_curlHandler) {
            if (function_exists('curl_reset')) {
                curl_reset(self::$_curlHandler);
            } else {
                my_curl_reset(self::$_curlHandler);
            }
        } else {
            self::$_curlHandler = curl_init();
        }
        curl_setopt(self::$_curlHandler, CURLOPT_URL, $rq['url']);
        switch (true) {
            case isset($rq['method']) && in_array(strtolower($rq['method']), ['get', 'post', 'put', 'delete', 'head']):
                $method = strtoupper($rq['method']);
                break;
            case isset($rq['data']):
                $method = 'POST';
                break;
            default:
                $method = 'GET';
        }
        $header = isset($rq['header']) ? $rq['header'] : [];
        $header[] = 'Method:'.$method;
        $header[] = 'User-Agent:'.Conf::getUA();
        $header[] = 'Connection: keep-alive';
        if ('POST' == $method) {
            $header[] = 'Expect: ';
        }

        isset($rq['host']) && $header[] = 'Host:'.$rq['host'];
        curl_setopt(self::$_curlHandler, CURLOPT_HTTPHEADER, $header);
        curl_setopt(self::$_curlHandler, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt(self::$_curlHandler, CURLOPT_CUSTOMREQUEST, $method);
        isset($rq['timeout']) && curl_setopt(self::$_curlHandler, CURLOPT_TIMEOUT, $rq['timeout']);
        isset($rq['data']) && in_array($method, ['POST', 'PUT']) && curl_setopt(self::$_curlHandler, CURLOPT_POSTFIELDS, $rq['data']);
        $ssl = substr($rq['url'], 0, 8) == 'https://' ? true : false;
        if (isset($rq['cert'])) {
            curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt(self::$_curlHandler, CURLOPT_CAINFO, $rq['cert']);
            curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 2);
            self::setCurlSSLVersion($rq);
        } elseif ($ssl) {
            curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, false); //true any ca
            curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 0); //not check the names
            self::setCurlSSLVersion($rq);
        }
        $ret = curl_exec(self::$_curlHandler);
        self::$_httpInfo = curl_getinfo(self::$_curlHandler);

        return $ret;
    }
public static function send($rq)
    {
        if (self::$_curlHandler) {
            if (function_exists('curl_reset')) {
                curl_reset(self::$_curlHandler);
            } else {
                my_curl_reset(self::$_curlHandler);
            }
        } else {
            self::$_curlHandler = curl_init();
        }
        curl_setopt(self::$_curlHandler, CURLOPT_URL, $rq['url']);
        switch (true) {
            case isset($rq['method']) && in_array(strtolower($rq['method']), ['get', 'post', 'put', 'delete', 'head']):
                $method = strtoupper($rq['method']);
                break;
            case isset($rq['data']):
                $method = 'POST';
                break;
            default:
                $method = 'GET';
        }
        $header = isset($rq['header']) ? $rq['header'] : [];
        $header[] = 'Method:'.$method;
        $header[] = 'User-Agent:'.Conf::getUA();
        $header[] = 'Connection: keep-alive';
        if ('POST' == $method) {
            $header[] = 'Expect: ';
        }

        isset($rq['host']) && $header[] = 'Host:'.$rq['host'];
        curl_setopt(self::$_curlHandler, CURLOPT_HTTPHEADER, $header);
        curl_setopt(self::$_curlHandler, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt(self::$_curlHandler, CURLOPT_CUSTOMREQUEST, $method);
        isset($rq['timeout']) && curl_setopt(self::$_curlHandler, CURLOPT_TIMEOUT, $rq['timeout']);
        isset($rq['data']) && in_array($method, ['POST', 'PUT']) && curl_setopt(self::$_curlHandler, CURLOPT_POSTFIELDS, $rq['data']);
        $ssl = substr($rq['url'], 0, 8) == 'https://' ? true : false;
        if (isset($rq['cert'])) {
            curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt(self::$_curlHandler, CURLOPT_CAINFO, $rq['cert']);
            curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 2);
            self::setCurlSSLVersion($rq);
        } elseif ($ssl) {
            curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, false); //true any ca
            curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 0); //not check the names
            self::setCurlSSLVersion($rq);
        }
        $ret = curl_exec(self::$_curlHandler);
        self::$_httpInfo = curl_getinfo(self::$_curlHandler);

        return $ret;
    }
public static function send ( $ rq ) { if ( self :: $ _curlHandler ) { if ( function_exists ( 'curl_reset' ) ) { curl_reset ( self :: $ _curlHandler ) ; } else { my_curl_reset ( self :: $ _curlHandler ) ; } } else { self :: $ _curlHandler = curl_init ( ) ; } curl_setopt ( self :: $ _curlHandler , CURLOPT_URL , $ rq [ 'url' ] ) ; switch ( true ) { case isset ( $ rq [ 'method' ] ) && in_array ( strtolower ( $ rq [ 'method' ] ) , [ 'get' , 'post' , 'put' , 'delete' , 'head' ] ) : $ method = strtoupper ( $ rq [ 'method' ] ) ; break ; case isset ( $ rq [ 'data' ] ) : $ method = 'POST' ; break ; default : $ method = 'GET' ; } $ header = isset ( $ rq [ 'header' ] ) ? $ rq [ 'header' ] : [ ] ; $ header [ ] = 'Method:' . $ method ; $ header [ ] = 'User-Agent:' . Conf :: getUA ( ) ; $ header [ ] = 'Connection: keep-alive' ; if ( 'POST' == $ method ) { $ header [ ] = 'Expect: ' ; } isset ( $ rq [ 'host' ] ) && $ header [ ] = 'Host:' . $ rq [ 'host' ] ; curl_setopt ( self :: $ _curlHandler , CURLOPT_HTTPHEADER , $ header ) ; curl_setopt ( self :: $ _curlHandler , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( self :: $ _curlHandler , CURLOPT_CUSTOMREQUEST , $ method ) ; isset ( $ rq [ 'timeout' ] ) && curl_setopt ( self :: $ _curlHandler , CURLOPT_TIMEOUT , $ rq [ 'timeout' ] ) ; isset ( $ rq [ 'data' ] ) && in_array ( $ method , [ 'POST' , 'PUT' ] ) && curl_setopt ( self :: $ _curlHandler , CURLOPT_POSTFIELDS , $ rq [ 'data' ] ) ; $ ssl = substr ( $ rq [ 'url' ] , 0 , 8 ) == 'https://' ? true : false ; if ( isset ( $ rq [ 'cert' ] ) ) { curl_setopt ( self :: $ _curlHandler , CURLOPT_SSL_VERIFYPEER , true ) ; curl_setopt ( self :: $ _curlHandler , CURLOPT_CAINFO , $ rq [ 'cert' ] ) ; curl_setopt ( self :: $ _curlHandler , CURLOPT_SSL_VERIFYHOST , 2 ) ; self :: setCurlSSLVersion ( $ rq ) ; } elseif ( $ ssl ) { curl_setopt ( self :: $ _curlHandler , CURLOPT_SSL_VERIFYPEER , false ) ; //true any ca curl_setopt ( self :: $ _curlHandler , CURLOPT_SSL_VERIFYHOST , 0 ) ; //not check the names self :: setCurlSSLVersion ( $ rq ) ; } $ ret = curl_exec ( self :: $ _curlHandler ) ; self :: $ _httpInfo = curl_getinfo ( self :: $ _curlHandler ) ; return $ ret ; }
send http request.

@param array $rq http请求信息
url        : 请求的url地址
method     : 请求方法，'get', 'post', 'put', 'delete', 'head'
data       : 请求数据，如有设置，则method为post
header     : 需要设置的http头部
host       : 请求头部host
timeout    : 请求超时时间
cert       : ca文件路径
ssl_version: SSL版本号

@return string http请求响应
send http request .