Get a new curl instance, encapsulated to make it mockable
@param string $url - Request url
@param string $method - HTTP method
@return CurlHttp get a new curl object
556129
protected function getCurlObject($url, $method = 'GET') {
		$curl = new CurlHttp();
		$curl->curl_setopt(CURLOPT_URL, $url);
		$curl->curl_setopt(CURLOPT_CUSTOMREQUEST, $method);
		$curl->curl_setopt(CURLOPT_RETURNTRANSFER, true);
		$curl->curl_setopt(CURLOPT_HTTPHEADER, ['apikey:' . $this->apikey] );
		$this->applyOptionsToCurl($curl);
		return $curl;
	}
747324
private function getUrl($method)
    {
        return sprintf(
            $this::API_URL,
            $this->getDc(),
            $this->getApiVersion(),
            $method
        );
    }
505321
public function setMethod($method)
    {
        parent::setMethod($method);
        if ($method !== 'GET') {
            switch ($method) {
                case 'POST':
                    $this->setOption(CURLOPT_POST, true);
                    break;
                default:
                    $this->setOption(CURLOPT_CUSTOMREQUEST, $this->method);
                    break;
            }
        }

        return $this;
    }
258363
public function update($url, $method) {
        $data = Values::of(array('Url' => $url, 'Method' => $method, ));

        $payload = $this->version->update(
            'POST',
            $this->uri,
            array(),
            $data
        );

        return new MemberInstance(
            $this->version,
            $payload,
            $this->solution['accountSid'],
            $this->solution['queueSid'],
            $this->solution['callSid']
        );
    }
989541
private function request($url, $params = [], $method = 'GET')
    {
        // Set URL & Header
        curl_setopt($this->curl, CURLOPT_URL, $this->url . $url);
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, array());

        //Add post vars
        if($method == 'POST')
        {
            curl_setopt($this->curl, CURLOPT_POST, count($params));
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
        }

        //Get result
        $result = curl_exec($this->curl);
        if($result === false)
            throw new \Exception('CURL error: ' . curl_error($this->curl));

        // decode results
        $result = json_decode($result, true);

        if(!is_array($result) || json_last_error())
            throw new \Exception('JSON decode error');

        return $result;

    }
798271
public static function request($method, $url, $payload = [], $curlOptions = [])
    {
        return static::_httpRequest($method, $url, $payload, $curlOptions);
    }
1354016
public static function request($url, $method = 'GET', array $parameter = [], array $option = [])
    {
        $curl = curl_init();

        curl_setopt_array($curl, [
            CURLOPT_HEADER => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_AUTOREFERER => true,
            CURLOPT_FOLLOWLOCATION => true,
        ]);

        if (isset($option[CURLOPT_CONNECTTIMEOUT])) {
            curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $option[CURLOPT_CONNECTTIMEOUT]);
        }

        if (isset($option[CURLOPT_TIMEOUT])) {
            curl_setopt($curl, CURLOPT_TIMEOUT, $option[CURLOPT_TIMEOUT]);
        }

        $query = empty($parameter) ? '' : http_build_query($parameter, '', '&');

        switch ($method) {
            case 'GET':
                if ($query) {
                    $url .= '?' . $query;
                }

                curl_setopt($curl, CURLOPT_HTTPGET, true);

                break;
            case 'POST':
                if ($query) {
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $query);
                }

                if (isset($option[CURLOPT_HTTPHEADER]) && is_array($option[CURLOPT_HTTPHEADER])) {
                    $option[CURLOPT_HTTPHEADER] = array_merge($option[CURLOPT_HTTPHEADER], [
                        'content-type: application/x-www-form-urlencoded',
                    ]);
                } else {
                    $option[CURLOPT_HTTPHEADER] = [
                        'content-type: application/x-www-form-urlencoded',
                    ];
                }

                curl_setopt($curl, CURLOPT_POST, true);

                break;
            default:
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);

                break;
        }

        if (!empty($option)) {
            curl_setopt_array($curl, $option);
        }

        curl_setopt($curl, CURLOPT_URL, $url);

        $body = curl_exec($curl);

        if (false === $body) {
            $error = curl_error($curl);
            $code = curl_errno($curl);

            curl_close($curl);
        }

        $header = (object) curl_getinfo($curl);

        curl_close($curl);

        if (mb_strpos($header->content_type, 'application/json') !== false) {
            $body = mb_substr($body, $header->header_size);
            $body = json_decode($body);
        }

        return (object) [
            'header' => $header,
            'body' => $body,
        ];
    }
268430
public function get($url, $data = [], $method = 'post') {

        $ch = curl_init($this->gitlab_host . '/api/v3' . $url);
       
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'PRIVATE-TOKEN:' . $this->private_key
        ));
        if($this->debug){
            curl_setopt($ch, CURLOPT_VERBOSE, true);
            if(!\sb\Gateway::$command_line){
                $curl_log = fopen("php://temp", 'rw');
                curl_setopt($ch, CURLOPT_STDERR, $curl_log);
            }
            
        }
         
       
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
        if ($data) {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            if ($method != 'post') {
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
            }
        }

        $error = curl_error($ch);
        $error_no = curl_errno($ch);
      
        if ($error_no) {
            throw(new \Exception($error . ': ' . $error_no));
        }
        $data = json_decode(curl_exec($ch));
        
        if($this->debug && !\sb\Gateway::$command_line){
            rewind($curl_log);
            $output= fread($curl_log, 2048);
            echo "<pre>". print_r($output, 1). "</pre>";
            fclose($curl_log);

        }
        
        return $data;
    }
464585
protected function createRequest($method, $url, $requestHeaders, $requestPayload, $protocolVersion)
    {
        $request = new Request(
            $method,
            $url,
            $requestHeaders,
            $requestPayload,
            $protocolVersion
        );

        return $request;
    }
667809
private function performRequest($method, $url, $options) {

        try {
            switch ($method) {
                case 'GET':
                    return json_decode($this->client->get($url, $options)->getBody(), true);
                case 'POST':
                    return json_decode($this->client->post($url, $options)->getBody(), true);
                case 'PUT':
                    return json_decode($this->client->put($url, $options)->getBody(), true);
                case 'DELETE':
                    return json_decode($this->client->delete($url, $options)->getBody(), true);
                default:
                    return null;
            }
        } catch (RequestException $e) {
            throw ApiException::create($e);
        }
    }
1132501
public function withMethod($method)
    {
        if ($this->getMethod() === $method) {
            return $this;
        }

        $newInstance = clone $this;
        $newInstance->setMethod($method);
        return $newInstance;
    }
977733
public function request(string $url, string $method = Request::METHOD_GET, array $postFields = [],
                            string $apiUrl = null): array
    {
        /** Building url */
        if (null === $apiUrl) {
            $apiUrl = $this->getApiUrl();
        }
        $url   = $apiUrl . $url;
        $query = [];

        /**
         * OAuth2 Key/Secret authentication
         *
         * @see https://developer.github.com/v3/#oauth2-keysecret
         */
        if (null !== $this->getClientId() && null !== $this->getClientSecret()) {
            $query['client_id']     = $this->getClientId();
            $query['client_secret'] = $this->getClientSecret();
        } /**
         * Basic authentication via OAuth2 Token (sent as a parameter)
         *
         * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter
         */ else if ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) {
            $query['access_token'] = $this->getToken();
        }

        /**
         * Pagination
         * Requests that return multiple items will be paginated to 30 items by default.
         * You can specify further pages with the ?page parameter.
         * For some resources, you can also set a custom page size up to 100 with the ?per_page parameter.
         * Note that for technical reasons not all endpoints respect the ?per_page parameter,
         *
         * @see https://developer.github.com/v3/#pagination
         */
        if (null !== $this->getPagination()) {
            if (null !== $this->getPagination()->getPage()) {
                $query['page'] = $this->getPagination()->getPage();
            }
            if (null !== $this->getPagination()->getLimit()) {
                $query['per_page'] = $this->getPagination()->getLimit();
            }
        }

        /**
         * Add URL-encoded query string parameters
         */
        if (!empty($query)) {
            $url .= (strstr($url, '?') !== false ? '&' : '?');
            $url .= http_build_query($query);
        }

        /** Call curl */
        $curl = new CurlClient();
        $curl->setOption([
            CURLOPT_USERAGENT      => self::USER_AGENT,
            CURLOPT_TIMEOUT        => $this->getTimeout(),
            CURLOPT_HEADER         => false, // Use $client->getHeaders() to get full header
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTPHEADER     => [
                'Accept: ' . $this->getAccept(),
                'Content-Type: ' . $this->getContentType()
            ],
            CURLOPT_URL            => $url
        ]);

        /**
         * Basic authentication via username and Password
         *
         * @see https://developer.github.com/v3/auth/#via-username-and-password
         */
        if (!empty($this->getHttpAuth())) {
            if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) {
                $curl->setOption([
                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
                    CURLOPT_USERPWD  => $this->getHttpAuth()['username']
                ]);
            } else {
                $curl->setOption([
                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
                    CURLOPT_USERPWD  => sprintf('%s:%s', $this->getHttpAuth()['username'],
                        $this->getHttpAuth()['password'])
                ]);
            }
        }

        if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) {
            /**
             * Basic authentication via OAuth token
             *
             * @see https://developer.github.com/v3/auth/#via-oauth-tokens
             **/
            if ($this->getAuthentication() === self::OAUTH_AUTH) {
                $curl->setOption([
                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
                    CURLOPT_USERPWD  => sprintf('%s:x-oauth-basic', $this->getToken())
                ]);
            } /**
             * Basic authentication via OAuth2 Token (sent in a header)
             *
             * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header
             */ else if ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) {
                $curl->setOption([
                    CURLOPT_HTTPAUTH   => CURLAUTH_BASIC,
                    CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())]
                ]);
            }
        }

        /** Methods */
        switch ($method) {
            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */
            case Request::METHOD_DELETE:
                /** @see http://tools.ietf.org/html/rfc5789 */
            case Request::METHOD_PATCH:
                $curl->setOption([
                    CURLOPT_CUSTOMREQUEST => $method,
                    CURLOPT_POST          => true,
                    CURLOPT_POSTFIELDS    => json_encode(array_filter($postFields))
                ]);
                break;

            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */
            case Request::METHOD_GET:
                $curl->setOption(CURLOPT_HTTPGET, true);
                break;

            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */
            case Request::METHOD_HEAD:
                $curl->setOption([
                    CURLOPT_CUSTOMREQUEST => $method,
                    CURLOPT_NOBODY        => true
                ]);
                break;

            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */
            case Request::METHOD_POST:
                $curl->setOption([
                    CURLOPT_POST       => true,
                    CURLOPT_POSTFIELDS => json_encode(array_filter($postFields))
                ]);
                break;

            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */
            case Request::METHOD_PUT:
                $curl->setOption([
                    CURLOPT_CUSTOMREQUEST => $method,
                    CURLOPT_PUT           => true,
                    CURLOPT_HTTPHEADER    => [
                        'X-HTTP-Method-Override: PUT',
                        'Content-type: application/x-www-form-urlencoded'
                    ]
                ]);
                break;

            default:
                break;
        }

        $curl->success(function (CurlClient $instance) {
            $this->headers = $instance->getHeaders();
            $this->success = $instance->getResponse();
            $data          = json_decode($this->success, true);
            if (JSON_ERROR_NONE === json_last_error()) {
                $this->success = $data;
            }
        });
        $curl->error(function (CurlClient $instance) {
            $this->headers = $instance->getHeaders();
            $this->failure = $instance->getResponse();
            $data          = json_decode($this->failure, true);
            if (JSON_ERROR_NONE === json_last_error()) {
                $this->failure = $data;
            }
        });
        $curl->perform();

        return (array)($this->success ?? $this->failure);
    }
993704
protected function configureHTTPMethod($method)
    {
        switch ($method) {
            case self::HTTP_GET:
                break;
            case self::HTTP_POST:
                return $this->addCurlOption(CURLOPT_POST, TRUE);
            default:
                return $this->addCurlOption(CURLOPT_CUSTOMREQUEST, $method);
        }
        return TRUE;
    }
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;
    }
338033
public function makeRequest($url, $method = 'GET')
    {
        try {
            [$url, $parameters] = $this->getRequestUrlAndParameters($url, $method === 'GET');
            return $this->response = $this->client->request($method, $url, $parameters);
        } catch (RequestException $e) {
            $this->printErrorMessage(Psr7\str($e->getRequest()), false);
            if ($e->hasResponse()) {
                $this->response = $e->getResponse();
                $this->printErrorMessage(Psr7\str($e->getResponse()), false);
            }
        }
        return false;
    }
146499
static function CurlRequest($method, $url, $data, $verify_cert = false, $timeout = 30)
	{
		// if the data provided is in array format, convert it to a querystring
		$qs = HttpRequest::ArrayToQueryString($data);

		$agent = "verysimple::HttpRequest";

		// $header[] = "Accept: text/vnd.wap.wml,*.*";

		$fp = null;

		if ($method == "POST")
		{
			$ch = curl_init($url);
			curl_setopt($ch,		CURLOPT_POST, 1);
			curl_setopt($ch,		CURLOPT_POSTFIELDS, $qs);
		}
		elseif ($method == 'PUT')
		{
			$ch = curl_init($url);
			curl_setopt($ch, CURLOPT_PUT, true);

			if ($data)
			{
				// with a PUT request the body must be written to a file stream
				$fp = fopen('php://temp/maxmemory:256000', 'w');
				if (!$fp) {
					throw new Exception('Unable to write to php://temp for PUT request');
				}
				fwrite($fp, $data);
				fseek($fp, 0);

				// if the PUT request contains JSON data then add the content type header
				if (json_encode($data)) curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json") );

				curl_setopt($ch, CURLOPT_INFILE, $fp);
				curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
				curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
			}

		}
		else
		{
			$full_url = $url . ($qs ? "?" . $qs : "");
			$ch = curl_init($full_url);
		}

		curl_setopt($ch,		CURLOPT_HTTPHEADER, array("Expect:  ") );  //Fixes the HTTP/1.1 417 Expectation Failed Bug
		
		curl_setopt($ch,		CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($ch,		CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch,		CURLOPT_VERBOSE, 0); ########### debug
		curl_setopt($ch,	    CURLOPT_USERAGENT, $agent);
		curl_setopt($ch,		CURLOPT_SSL_VERIFYPEER, $verify_cert);
		curl_setopt($ch,		CURLOPT_NOPROGRESS, 1);
		// curl_setopt($ch,	    CURLOPT_HTTPHEADER, $header);
		// curl_setopt($ch,		CURLOPT_COOKIEJAR, "curl_cookie");
		// curl_setopt($ch,		CURLOPT_COOKIEFILE, "curl_cookie");
		curl_setopt($ch,		CURLOPT_TIMEOUT,$timeout);

		$tmp = curl_exec ($ch);
		$error = curl_error($ch);

		if ($fp) @fclose($fp); // if a PUT request had body data, close the file stream

		if ($error != "") {$tmp .= $error;}
		curl_close ($ch);

		return $tmp;
	}
593038
public function execute($method, $url, array $post = array())
	{
		$curl = curl_init($url);

		curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
		curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
		curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent());

		if ($post)
		{
			curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
		}

		$response = curl_exec($curl);

		if ($response === FALSE OR curl_getinfo($curl, CURLINFO_HTTP_CODE) !== 200)
		{
			throw new Exception_Curl('Curl: Download Error: :error, status :status on url :url', array(':url' => $url, ':status' => curl_getinfo($curl, CURLINFO_HTTP_CODE), ':error' => curl_error($curl)));
		}

		$this->_current_url = urldecode(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));

		return $response;
	}