src/LearnositySdk/Request/Remote.php
private function request($url, $post = false, $options = array())
    {
        $defaults = array(
            'connect_timeout'   => 10,
            'timeout'           => 40,
            'headers'           => array(),
            'encoding'          => 'utf-8',
            'ssl_verify'        => true
        );

        $options = array_merge($defaults, $options);

        // normalize the headers
        $options['headers'] = $this->normalizeRequestHeaders($options['headers']);

        $ch = curl_init();

        $params = array(
            CURLOPT_URL            => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_ENCODING       => $options['encoding'],
            CURLOPT_AUTOREFERER    => true,
            CURLOPT_CONNECTTIMEOUT => $options['connect_timeout'],
            CURLOPT_TIMEOUT        => $options['timeout'],
            CURLOPT_MAXREDIRS      => 10,
            CURLOPT_SSL_VERIFYPEER => $options['ssl_verify']
        );

        if (!empty($options['headers'])) {
            $params[CURLOPT_HTTPHEADER] = $options['headers'];
        }

        if (!empty($post)) {
            $params[CURLOPT_POST] = true;
            $params[CURLOPT_POSTFIELDS] = $post;
        }

        curl_setopt_array($ch, $params);

        $body          = curl_exec($ch);
        $error_code    = curl_errno($ch);
        $error_message = curl_error($ch);
        $response      = curl_getinfo($ch);

        curl_close($ch);

        $response['error_code']    = $error_code;
        $response['error_message'] = $error_message;
        $response['body']          = $body;

        $this->result = $response;
    }
private function request($url, $post = false, $options = array())
    {
        $defaults = array(
            'connect_timeout'   => 10,
            'timeout'           => 40,
            'headers'           => array(),
            'encoding'          => 'utf-8',
            'ssl_verify'        => true
        );

        $options = array_merge($defaults, $options);

        // normalize the headers
        $options['headers'] = $this->normalizeRequestHeaders($options['headers']);

        $ch = curl_init();

        $params = array(
            CURLOPT_URL            => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_ENCODING       => $options['encoding'],
            CURLOPT_AUTOREFERER    => true,
            CURLOPT_CONNECTTIMEOUT => $options['connect_timeout'],
            CURLOPT_TIMEOUT        => $options['timeout'],
            CURLOPT_MAXREDIRS      => 10,
            CURLOPT_SSL_VERIFYPEER => $options['ssl_verify']
        );

        if (!empty($options['headers'])) {
            $params[CURLOPT_HTTPHEADER] = $options['headers'];
        }

        if (!empty($post)) {
            $params[CURLOPT_POST] = true;
            $params[CURLOPT_POSTFIELDS] = $post;
        }

        curl_setopt_array($ch, $params);

        $body          = curl_exec($ch);
        $error_code    = curl_errno($ch);
        $error_message = curl_error($ch);
        $response      = curl_getinfo($ch);

        curl_close($ch);

        $response['error_code']    = $error_code;
        $response['error_message'] = $error_message;
        $response['body']          = $body;

        $this->result = $response;
    }
private function request ( $ url , $ post = false , $ options = array ( ) ) { $ defaults = array ( 'connect_timeout' => 10 , 'timeout' => 40 , 'headers' => array ( ) , 'encoding' => 'utf-8' , 'ssl_verify' => true ) ; $ options = array_merge ( $ defaults , $ options ) ; // normalize the headers $ options [ 'headers' ] = $ this -> normalizeRequestHeaders ( $ options [ 'headers' ] ) ; $ ch = curl_init ( ) ; $ params = array ( CURLOPT_URL => $ url , CURLOPT_RETURNTRANSFER => true , CURLOPT_FOLLOWLOCATION => true , CURLOPT_ENCODING => $ options [ 'encoding' ] , CURLOPT_AUTOREFERER => true , CURLOPT_CONNECTTIMEOUT => $ options [ 'connect_timeout' ] , CURLOPT_TIMEOUT => $ options [ 'timeout' ] , CURLOPT_MAXREDIRS => 10 , CURLOPT_SSL_VERIFYPEER => $ options [ 'ssl_verify' ] ) ; if ( ! empty ( $ options [ 'headers' ] ) ) { $ params [ CURLOPT_HTTPHEADER ] = $ options [ 'headers' ] ; } if ( ! empty ( $ post ) ) { $ params [ CURLOPT_POST ] = true ; $ params [ CURLOPT_POSTFIELDS ] = $ post ; } curl_setopt_array ( $ ch , $ params ) ; $ body = curl_exec ( $ ch ) ; $ error_code = curl_errno ( $ ch ) ; $ error_message = curl_error ( $ ch ) ; $ response = curl_getinfo ( $ ch ) ; curl_close ( $ ch ) ; $ response [ 'error_code' ] = $ error_code ; $ response [ 'error_message' ] = $ error_message ; $ response [ 'body' ] = $ body ; $ this -> result = $ response ; }
Makes a cURL request to an endpoint with an optional request
payload and cURL options.

@param  string $url      Full URL of where to POST the request
@param  array  $request  Payload of request
@param  bool   $options  Optional Curl options
@return void
Makes a cURL request to an endpoint with an optional request payload and cURL options .