Executes a Curl.

@param  String $method
@param  String $location
@return CurlClientResponse
@throws Inconsistent
495803
public function execute($method, $location)
    {
        curl_setopt_array($this->curl, array(
            CURLOPT_URL => $location,
            CURLOPT_COOKIE => $this->getRequestCookies(),
            CURLOPT_CUSTOMREQUEST => $method,
        ));

        if (!$response = curl_exec($this->curl)) {
            $this->restart();
            throw new EmptyResponseException($this, $location);
        }

        $response = new CurlClientResponse($response);
        $this->cookies = array_merge($this->cookies, $response->getCookies());

        if ($this->restart == true) {
            $this->restart();
        }

        return $response;
    }
1314034
public function request($method, $url, $params = array(), $vars = array()) {
    $this->request = curl_init();

    $this->setRequestMethod($method);
    $this->setOptions($url, $method, $params, $vars);

    $data = curl_exec($this->request);

    if ($data === false) {
      throw new \Exception('Curl Error: ' . curl_error($this->request));
    }

    $response = new HttpResponse($data);

    curl_close($this->request);

    return $response;
  }
374614
protected static function _httpRequest( $method = self::GET, $url, $payload = array(), $curlOptions = array() )
    {
        if ( !static::contains( $method ) )
        {
            throw new \InvalidArgumentException( 'Invalid method "' . $method . '" specified.' );
        }

        //	Reset!
        static::$_lastResponseHeaders = static::$_lastHttpCode = static::$_error = static::$_info = $_tmpFile = null;

        //	Build a curl request...
        $_curl = curl_init( $url );

        //	Default CURL options for this method
        $_curlOptions = array(
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER         => true,
            CURLINFO_HEADER_OUT    => true,
            CURLOPT_SSL_VERIFYPEER => false,
        );

        //	Merge in the global options if any
        if ( !empty( static::$_curlOptions ) )
        {
            $curlOptions = array_merge(
                $curlOptions,
                static::$_curlOptions
            );
        }

        //	Add/override user options
        if ( !empty( $curlOptions ) )
        {
            foreach ( $curlOptions as $_key => $_value )
            {
                $_curlOptions[$_key] = $_value;
            }
        }

        if ( null !== static::$_userName || null !== static::$_password )
        {
            $_curlOptions[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
            $_curlOptions[CURLOPT_USERPWD] = static::$_userName . ':' . static::$_password;
        }

        switch ( $method )
        {
            case static::GET:
                //	Do nothing, like the goggles...
                break;

            case static::PUT:
                if (static::$putAsFile)
                {
                    $_payload = json_encode(!empty($payload) ? $payload : []);

                    $_tmpFile = tmpfile();
                    fwrite($_tmpFile, $_payload);
                    rewind($_tmpFile);

                    $_curlOptions[CURLOPT_PUT] = true;
                    $_curlOptions[CURLOPT_INFILE] = $_tmpFile;
                    $_curlOptions[CURLOPT_INFILESIZE] = mb_strlen($_payload);
                }
                else
                {
                    $_curlOptions[CURLOPT_CUSTOMREQUEST] = static::PUT;
                    $_curlOptions[CURLOPT_POSTFIELDS] = $payload;
                }
                break;

            case static::POST:
                $_curlOptions[CURLOPT_POST] = true;
                $_curlOptions[CURLOPT_POSTFIELDS] = $payload;
                break;

            case static::HEAD:
                $_curlOptions[CURLOPT_NOBODY] = true;
                break;

            case static::PATCH:
                $_curlOptions[CURLOPT_CUSTOMREQUEST] = static::PATCH;
                $_curlOptions[CURLOPT_POSTFIELDS] = $payload;
                break;

            case static::MERGE:
            case static::DELETE:
                /** Merge && Delete have payloads, but they and Options/Copy need CURLOPT_CUSTOMREQUEST set so just fall through... */
                $_curlOptions[CURLOPT_POSTFIELDS] = $payload;
            //  intentional drop through...
            case static::OPTIONS:
            case static::COPY:
                $_curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
                break;
        }

        if ( null !== static::$_hostPort && !isset( $_curlOptions[CURLOPT_PORT] ) )
        {
            $_curlOptions[CURLOPT_PORT] = static::$_hostPort;
        }

        //	Set our collected options
        curl_setopt_array( $_curl, $_curlOptions );

        //	Make the call!
        $_result = curl_exec( $_curl );

        static::$_info = curl_getinfo( $_curl );
        static::$_lastHttpCode = Option::get( static::$_info, 'http_code' );
        static::$_responseHeaders = curl_getinfo( $_curl, CURLINFO_HEADER_OUT );
        static::$_responseHeadersSize = curl_getinfo( $_curl, CURLINFO_HEADER_SIZE );

        if ( static::$_debug )
        {
            //	@todo Add debug output
        }

        if ( false === $_result )
        {
            static::$_error = array(
                'code'    => curl_errno( $_curl ),
                'message' => curl_error( $_curl ),
            );
        }
        elseif ( true === $_result )
        {
            //	Worked, but no data...
            $_result = null;
        }
        else
        {
            //      Split up the body and headers if requested
            if ( $_curlOptions[CURLOPT_HEADER] )
            {
                if ( false === strpos( $_result, "\r\n\r\n" ) || empty( static::$_responseHeadersSize ) )
                {
                    $_headers = $_result;
                    $_body = null;
                }
                else
                {
                    $_headers = substr( $_result, 0, static::$_responseHeadersSize );
                    $_body = substr( $_result, static::$_responseHeadersSize );
                }

                if ( $_headers )
                {
                    static::$_lastResponseHeaders = array();
                    $_raw = explode( "\r\n", $_headers );

                    if ( !empty( $_raw ) )
                    {
                        $_first = true;

                        foreach ( $_raw as $_line )
                        {
                            //	Skip the first line (HTTP/1.x response)
                            if ( $_first || preg_match( '/^HTTP\/[0-9\.]+ [0-9]+/', $_line ) )
                            {
                                $_first = false;
                                continue;
                            }

                            $_parts = explode( ':', $_line, 2 );

                            if ( !empty( $_parts ) )
                            {
                                static::$_lastResponseHeaders[trim( $_parts[0] )] = count( $_parts ) > 1 ? trim( $_parts[1] ) : null;
                            }
                        }
                    }
                }

                $_result = $_body;
            }

            //	Attempt to auto-decode inbound JSON
            if ( !empty( $_result ) && false !== stripos( Option::get( static::$_info, 'content_type' ), 'application/json', 0 ) )
            {
                try
                {
                    if ( false !== ( $_json = @json_decode( $_result, static::$_decodeToArray ) ) )
                    {
                        $_result = $_json;
                    }
                }
                catch ( \Exception $_ex )
                {
                    //	Ignored
                    Log::debug( 'Exception decoding result: ' . $_ex->getMessage() );
                }
            }

            //	Don't confuse error with empty data...
            if ( false === $_result )
            {
                $_result = null;
            }
        }

        @curl_close( $_curl );

        //	Close temp file if any
        if ( null !== $_tmpFile )
        {
            @fclose( $_tmpFile );
        }

        return $_result;
    }
591516
public function execute($method, $url, array $query = [], array $headers = [])
    {
        // Merge global and request headers
        $headers = array_merge(
            Arr::get($this->config, 'headers', []),
            $headers
        );

        // Merge global and request queries
        $query = array_merge(
            Arr::get($this->config, 'query', []),
            $query
        );

        $this->errors = null;

        $curl = curl_init();

        // Set options
        curl_setopt_array($curl, [
            CURLOPT_URL => $this->getUrl($url),
            CURLOPT_HTTPHEADER => $headers,
            CURLOPT_CONNECTTIMEOUT => 20,
            CURLOPT_TIMEOUT => 90,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_SSL_VERIFYPEER => 0,
            CURLOPT_SSL_VERIFYHOST => 0,
            CURLOPT_HEADER => 1,
            CURLINFO_HEADER_OUT => 1,
            CURLOPT_VERBOSE => 1,
        ]);

        // Setup method specific options
        switch ($method) {
            case 'PUT':
            case 'PATCH':
            case 'POST':
                curl_setopt_array($curl, [
                    CURLOPT_CUSTOMREQUEST => $method,
                    CURLOPT_POST => true,
                    CURLOPT_POSTFIELDS => $query,
                ]);
                break;

            case 'DELETE':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
                break;

            default:
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
                break;
        }

        // Make request
        curl_setopt($curl, CURLOPT_HEADER, true);
        $response = curl_exec($curl);

        // Set HTTP response code
        $this->http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        // Set errors if there are any
        if (curl_errno($curl)) {
            $this->errors = curl_error($curl);
        }

        // Parse body
        $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        $header = substr($response, 0, $header_size);
        $body = substr($response, $header_size);

        curl_close($curl);

        return [$body, $this->parseHeaders($header)];
    }
1516
protected function sendApiCall($verb, $location)
    {
        try {
            $this->detectInvalidJsonFields();
            $response = $this->client->sendRequest($verb, $location, $this->postFields);

            $entity = $this->getItems($response->getBody());
            if (isset($entity[0])) {
                $this->setFields($entity[0]);
            }

            return $response;
        } catch (ClientException $e) {
            if ($e->getResponse() !== null) {
                $entity = $this->getItems($e->getResponse()->getBody());

                if (isset($entity[0]['validation_messages'])) {
                    throw new ValidationException(
                        $entity[0]['validation_messages'],
                        $this->postFields,
                        $e->getResponse()->getStatusCode(),
                        isset($entity[0]['errorCode']) ? $entity[0]['errorCode'] : null
                    );
                } else {
                    throw new EntityException(
                        'Exception received from api client: ' . $e->getMessage(),
                        $e->getCode(),
                        $e->getResponse()->getStatusCode(),
                        isset($entity[0]['errorCode']) ? $entity[0]['errorCode'] : null
                    );
                }
            } else {
                throw new EntityException(
                    'Exception received from api client: ' . $e->getMessage(),
                    $e->getCode()
                );
            }
        }
    }
22578
private function executeAuthMethod($method)
    {
        foreach ($this->auths as $auth) {
            if (is_callable([$auth, $method], true)) {
                if ($data = $auth->{$method}()) return $data;
            }
        }

        return false;
    }
754348
private function sendRequest($method, $url, $data = false)
    {
        $curlHandler = curl_init();
        curl_setopt($curlHandler, CURLOPT_HTTPHEADER, $this->formatUserAgentInfo());

        if ($method === 'POST') {
            curl_setopt($curlHandler, CURLOPT_POST, 1);

            if ($data) {
                curl_setopt($curlHandler, CURLOPT_POSTFIELDS, json_encode($data));
            }
        }

        if ($method === 'GET' && $data) {
            $url = sprintf("%s?%s", $url, http_build_query($data));
        }

        curl_setopt($curlHandler, CURLOPT_URL, $url);
        curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);

        $this->response = curl_exec($curlHandler);

        $this->curlInfo = curl_getinfo($curlHandler);
        $httpCode = curl_getinfo($curlHandler)['http_code'];

        if ($httpCode >= 400) {
            throw new \Exception($this->json()['status'], $httpCode);
        }

        curl_close($curlHandler);

        return $this;
    }
244938
protected function execute_curl($options) {
		$ch = curl_init();
		curl_setopt_array($ch, $options);
		$returned = curl_exec($ch);
		$response = HttpClientResponse::instance_from_curl($ch, $returned);
		curl_close($ch);
		return $response;
	}
848662
public function put($method, array $data)
    {
        //set cURL transfer option for post request
        // and get ouput
        return $this->createEndPoint($method)
                    ->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT')
                    ->setOpt(CURLOPT_POSTFIELDS, http_build_query($data))
                    ->exec();
    }
1269826
private function request($url, $method, $authorization, $postfields)
    {
        /* Curl settings */
        $options = [
            // CURLOPT_VERBOSE => true,
            CURLOPT_CAINFO => __DIR__ . DIRECTORY_SEPARATOR . 'cacert.pem',
            CURLOPT_CONNECTTIMEOUT => $this->connectionTimeout,
            CURLOPT_HEADER => true,
            CURLOPT_HTTPHEADER => ['Accept: application/json', $authorization, 'Expect:'],
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYHOST => 2,
            CURLOPT_SSL_VERIFYPEER => true,
            CURLOPT_TIMEOUT => $this->timeout,
            CURLOPT_URL => $url,
            CURLOPT_USERAGENT => $this->userAgent,
            CURLOPT_ENCODING => 'gzip',
        ];
        if (!empty($this->proxy)) {
            $options[CURLOPT_PROXY] = $this->proxy['CURLOPT_PROXY'];
            $options[CURLOPT_PROXYUSERPWD] = $this->proxy['CURLOPT_PROXYUSERPWD'];
            $options[CURLOPT_PROXYPORT] = $this->proxy['CURLOPT_PROXYPORT'];
            $options[CURLOPT_PROXYAUTH] = CURLAUTH_BASIC;
            $options[CURLOPT_PROXYTYPE] = CURLPROXY_HTTP;
        }
        switch ($method) {
            case 'GET':
                break;
            case 'POST':
                $options[CURLOPT_POST] = true;
                $options[CURLOPT_POSTFIELDS] = Util::buildHttpQuery($postfields);
                break;
            case 'DELETE':
                $options[CURLOPT_CUSTOMREQUEST] = 'DELETE';
                break;
            case 'PUT':
                $options[CURLOPT_CUSTOMREQUEST] = 'PUT';
                break;
        }
        if (in_array($method, ['GET', 'PUT', 'DELETE']) && !empty($postfields)) {
            $options[CURLOPT_URL] .= '?' . Util::buildHttpQuery($postfields);
        }
        $curlHandle = curl_init();
        curl_setopt_array($curlHandle, $options);
        $response = curl_exec($curlHandle);
        // Throw exceptions on cURL errors.
        if (curl_errno($curlHandle) > 0) {
            throw new TwitterOAuthException(curl_error($curlHandle), curl_errno($curlHandle));
        }
        $this->response->setHttpCode(curl_getinfo($curlHandle, CURLINFO_HTTP_CODE));
        $parts = explode("\r\n\r\n", $response);
        $responseBody = array_pop($parts);
        $responseHeader = array_pop($parts);
        $this->response->setHeaders($this->parseHeaders($responseHeader));
        curl_close($curlHandle);
        return $responseBody;
    }
361103
private function _curl($url, $data = '', $method = 'get')
    {
        $parStr = '';
        if (is_array($data)) {
            $parStr = http_build_query($data);
        } else {
            $parStr = $data;
        }

        if (strtolower($method) == 'get') {
            $json = file_get_contents(rtrim($url, '?').'?'.$parStr);
        } else {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $parStr);
            $json = curl_exec($ch);
            curl_close($ch);
        }

        $result = json_decode($json, true);

        if (isset($result['errcode']) and $result['errcode'] != 0) {
            $this->_log("Error-{$method}-{$url}", $json, $data);
            return false;
        }

        return $result;
    }
1128152
private function redirect($method) {

		$this -> setUrl();
		$this -> setDomain();
		$this -> setMethod($method);
		
		Router :: setRedirect(true);

		return Router :: execute();
	}
88997
public function get($method, $data = array())
    {
        //set cURL transfer option for get request
        // and get ouput
        return $this->createEndPoint($method, $data)
                    ->setOpt(CURLOPT_CUSTOMREQUEST, 'GET')
                    ->setopt(CURLOPT_HTTPGET, true)
                    ->exec();
    }
626528
public function __doRequest($request, $location, $action, $version, $one_way = 0) {

		$headers = array(
			'User-Agent: PHP-SOAP',
			'Content-Type: text/xml; charset=utf-8',
			'SOAPAction: "' . $action . '"',
			'Expect: 100-continue',
			'Connection: Keep-Alive'
		);

		$this->__last_request_headers = $headers;
		$location = $this->sanitizeUrl($location);

		$ch = curl_init($location);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

		curl_setopt($ch, CURLOPT_POST, TRUE);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

		curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
		curl_setopt($ch, CURLOPT_FAILONERROR, FALSE);
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

		curl_setopt($ch, CURLOPT_USERPWD, $this->Username . ':' . $this->Password);
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);

		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$response = curl_exec($ch);

		if (($info = curl_getinfo($ch)) && $info['http_code'] == 200) {
			return $response;
		}
		else {
			if ($info['http_code'] == 401) {
				throw new \Exception ('Access Denied', 401);
			}
			else {
				if (curl_errno($ch) != 0) {
					throw new \Exception(curl_error($ch), curl_errno($ch));
				}
				else {
					throw new \Exception('Error', $info['http_code']);
				}
			}
		}
	}
1289330
public function request($url, $method = 'get', $data = null, $curlOptions = array())
    {
        if (strtolower($method) === 'get')
        {
            $this->setGetfield($data);
        }
        else
        {
            $this->setPostfields($data);
        }

        return $this->buildOauth($url, $method)->performRequest(true, $curlOptions);
    }
798271
public static function request($method, $url, $payload = [], $curlOptions = [])
    {
        return static::_httpRequest($method, $url, $payload, $curlOptions);
    }
1317985
public function execute() {
        $ch = \curl_init();

        $this->setAuth($ch);
        try {
            switch (strtoupper($this->method)) {
                case 'GET':
                    $this->executeGet($ch);
                    break;
                case 'POST':
                    $this->executePost($ch);
                    break;
                case 'PUT':
                    $this->executePut($ch);
                    break;
                case 'PATCH':
                    $this->executePatch($ch);
                    break;
                case 'DELETE':
                    $this->executeDelete($ch);
                    break;
                // This custom case is used to execute a Multipart PUT request
                case 'PUT_MP':
                    $this->method = 'PUT';
                    $this->executePutMultipart($ch);
                    break;
                case 'POST_MP':
                    $this->method = 'POST';
                    $this->executePostMultipart($ch);
                    break;
                default:
                    throw new \InvalidArgumentException('Current method (' . $this->method . ') is an invalid REST method.');
            }
        } catch (\InvalidArgumentException $e) {
            \curl_close($ch);
            throw $e;
        } catch (\Exception $e) {
            \curl_close($ch);
            throw $e;
        }
    }