Sends the request via curl

@param string $url       Relative url for the request
@param array $params     Parameters for the request
@param string $method    Request method
@return string
180293
public function sendRequest($url, $params, $method)
    {
        if($method=='POST')
        {
            if (!empty($params['file']))
                $ch = $this->initiateUpload($url, $params);
            else
                $ch = $this->initiatePost($url, $params);
        }
        else if($method=='GET')
        {
            $ch = $this->initiateGet($url, $params);
        }
        else if($method=='DELETE')
        {
            $ch = $this->initiateDelete($url, $params);
        }
        else{
            throw new \Exception("Method ".$method." not supported!");
        }

        if (! $ret = curl_exec($ch))
        {
            trigger_error(curl_error($ch));
        }

        curl_close($ch);
        return $ret;
    }
1044893
public function request(string $method, string $url, $options = []): array
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FAILONERROR, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        if (isset($options['body'])) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($options['body']) ? http_build_query($options['body']) : $options['body']);
        }
        if (SmsConfig::getTimeout() > 0) {
            curl_setopt($ch, CURLOPT_TIMEOUT, SmsConfig::getTimeout());
        }
        if (SmsConfig::getConnectTimeout()) {
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, SmsConfig::getConnectTimeout());
        }
        //https request
        if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
        if (isset($options['headers']) && is_array($options['headers']) && 0 < count($options['headers'])) {
            $http_headers = $this->getHttpHearders($options['headers']);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
        }
        $content = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return [$code, $content];
    }
787674
private function __sendCurl($urlPath, $method, $param)
    {
        $url = trim($this->apiBaseUrl, '/') . '/' . trim($urlPath, '/');

        if ($method == 'GET') {
            $query = http_build_query($param);
            $url = $url . '?' . $query;
        }

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_POSTFIELDS => $method == 'POST' ? json_encode($param) : '',
            CURLOPT_HTTPHEADER => array(
                "Cache-Control: no-cache",
                "Content-Type: application/json",
            ),
        ));

        $response = curl_exec($curl);
        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $error = curl_error($curl);
        curl_close($curl);

        return (object)array(
            'code' => $httpCode,
            'response' => $error ? $error : json_decode($response),
        );

    }
682702
public function request($method, $url, array $params = [])
    {
        if (!$this->authenticated()) {
            $this->authenticate();
        }

        if (!isset($params['query'])) {
            $params['query'] = [];
        }

        $params['query']['format'] = 'json';

        try {
            $response = $this->getHttpClient()->request($method, $url, $params);
        } catch (RequestException $e) {
            return $e->getResponse();
        }

        return $response;
    }
882470
protected function apiRequest($url, $params = array()) {
        if(! isset($params['api_key']) && $this->hasAttribute('api_key'))
            $params['key'] = $this->getAttribute('api_key');

        $query = http_build_query($params, '&');

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url . '?' . $query);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);

        return $output;
    }
198225
public function call($function, array $params = null, $method = 'GET')
    {
        $url = $this->endpointUrl($function);

        return $this->send($url, true, $params, $method);
    }
845025
private function __sendFileGetContents($urlPath, $method, $param)
    {
        $url = trim($this->apiBaseUrl, '/') . '/' . trim($urlPath, '/');

        if ($method == 'GET') {
            $query = http_build_query($param);
            $url = $url . '?' . $query;
        }

        $opts = array('http' =>
            array(
                'method' => $method,
                'timeout' => '30',
                'max_redirects' => '10',
                'ignore_errors' => '1',
                'header' => 'Content-type: application/json',
                'content' => $method == 'POST' ? json_encode($param) : ''
            )
        );

        $context = stream_context_create($opts);
        $result = file_get_contents($url, false, $context);

        //get http status code
        $response_header = explode(' ', $http_response_header[0]);
        $httpCode = (int)$response_header[1];


        return (object)array(
            'code' => $httpCode,
            'response' => json_decode($result),
        );
    }
516685
protected function doRequest($method, $path, array $params)
	{
		$ch = curl_init();

		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_TIMEOUT, 20);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, self::STRICT_SSL);
		curl_setopt($ch, CURLOPT_ENCODING, ''); // Signal that we support gzip

		$api_endpoint = trim($this->api_base_url, '/').'/'.trim($path, '/');

		if ($method == self::METHOD_GET) {
			curl_setopt($ch, CURLOPT_URL, $api_endpoint.'?'.http_build_query($params, '', '&'));
		} else {
			curl_setopt($ch, CURLOPT_URL, $api_endpoint);
			curl_setopt($ch, CURLOPT_POST, true);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
		}

		$body = curl_exec($ch);

        /* 77 = CURLE_SSL_CACERT_BADFILE (constant not defined in PHP though). */
		if (curl_errno($ch) == CURLE_SSL_CACERT || curl_errno($ch) == CURLE_SSL_PEER_CERTIFICATE || curl_errno($ch) == 77) {
			/*
			 * On some servers, the list of installed certificates is outdated or not present at all (the ca-bundle.crt
			 * is not installed). So we tell cURL which certificates we trust. Then we retry the requests.
			 */
			curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . DIRECTORY_SEPARATOR . "cacert.pem");
			$body = curl_exec($ch);
		}

		if (strpos(curl_error($ch), "certificate subject name 'mollie.nl' does not match target host") !== false) {
			/*
			 * On some servers, the wildcard SSL certificate is not processed correctly. This happens with OpenSSL 0.9.7
			 * from 2003.
			 */
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
			$body = curl_exec($ch);
		}

		$results = [
			'body'         => $body,
			'http_code'    => curl_getinfo($ch, CURLINFO_HTTP_CODE),
			'content_type' => curl_getinfo($ch, CURLINFO_CONTENT_TYPE),
			'code'         => curl_errno($ch), 
			'message'      => curl_error($ch),
		];

		curl_close($ch);

		return $results;
	}
100413
private function _socket($url, $params = array(), $method = self::METHOD) {
    $method = strtoupper($method);

    $parse = $this->_parseUrl($url);
    $content = $this->_buildRequestContent(
        $parse,
        $method,
        http_build_query($params)
    );
    if ($this->debug) {
      $this->debugInfo = $content;
    }

    $socket = fsockopen(
        $parse['host'],
        $parse["port"],
        $errno,
        $errstr,
        $this->connect_timeout
    );

    stream_set_timeout($socket, $this->timeout);

    if (!$socket) {
      throw new Exception("Connect " . $parse['host'] . ' fail.');
    }

    $response = '';
    fwrite($socket, $content);
    while($data = fgets($socket)) {
      $response .= $data;
    }
    fclose($socket);

    $ret = $this->_parseResponse($response);
    return $ret['result'];
  }
357306
protected function send($url, array $params)
    {
        $success = false;

        $rawResponse = $this->client->post($url, [
            'exceptions'      => false,
            'timeout'         => '80',
            'connect_timeout' => '30',
            'verify'          => true,
            'auth'            => [
                $this->config['client'],
                $this->config['token'],
            ],
            'headers' => [
                'Accept'         => 'application/json',
                'Accept-Charset' => 'utf-8',
                'Content-Type'   => 'application/x-www-form-urlencoded',
            ],
            'body' => $params,
        ]);

        if (substr((string) $rawResponse->getStatusCode(), 0, 1) === '2') {
            $response = json_decode($rawResponse->getBody(), true);
            $success = true;
        } else {
            $response = $this->responseError($rawResponse);
        }

        return $this->mapResponse($success, $response);
    }
994753
private function request($url, $method = 'GET', $postfields = array())
    {
        curl_setopt_array($this->ch, array(
            CURLOPT_USERAGENT => 'VK/1.0 (+https://github.com/vladkens/VK))',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_POST => ($method == 'POST'),
            CURLOPT_POSTFIELDS => $postfields,
            CURLOPT_URL => $url
        ));

        return curl_exec($this->ch);
    }
1010153
protected function composeRequestCurlOptions($method, $url, array $params)
    {
        $curlOptions = parent::composeRequestCurlOptions($method, $url, $params);

        // add HTTP Basic Authorization headers for getting access token
        // or add Bearer token for api requests
        if ($url == $this->tokenUrl) {
            $curlOptions[CURLOPT_HTTPHEADER][] = 'Authorization: Basic ' . base64_encode("{$params["client_id"]}:{$params["client_secret"]}");
        } elseif (strpos($url, $this->apiBaseUrl) !== false) {
            $curlOptions[CURLOPT_HTTPHEADER][] = 'Authorization: Bearer ' . $params['access_token'];
        }
        return $curlOptions;
    }
307682
private function request($method, $url, $params = [])
    {
        $this->getLogger()->debug('Creating a new request with received parameters');
        $options = [
            'headers' => null, 'body' => null
        ];
        // Multipart
        if (array_key_exists('multipart', $params)) {
            // Build the multipart message
            $options['body'] = new MultipartStream($params['multipart']);
        } else if (array_key_exists('json', $params)) {
            // Build the JSON body and content type
            $options['body'] = json_encode($params['json']);
            $options['headers'] = ['content-type' => 'application/json'];
        } else if ($method == 'POST' || $method == 'PUT' || $method == 'DELETE') {
            $options['headers'] = ['content-type' => 'application/x-www-form-urlencoded'];
            if (count($params) > 0) {
                $options['body'] = http_build_query($params, null, '&');
            }
        }
        $this->logger->debug('Getting Authenticated Request');
        $request = $this->provider->getAuthenticatedRequest($method, $this->provider->getCmsApiUrl() . rtrim($url, '/'), $this->getAccessToken(), $options);
        $this->logger->debug('Getting parsed response from Abstract Provider');
        return $this->provider->getParsedResponse($request);
    }
274314
public function post($url, array $params = [])
    {
        return $this->request($this->createUrl($url), self::METHOD_POST, $params);
    }
1173181
public function get($url, array $params = [])
    {
       $queryString = '?' . http_build_query($params);

       $url = $url . $queryString;

       $request = new Request(
            $url,
            'GET'
        );

        return $this->send($request);
    }
1278902
private function _request($method, $params = array(), $url = self::API_ENDPOINT) {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_USERAGENT, 'Elvanto_API-PHP/1.0.0');
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
		curl_setopt($ch, CURLOPT_TIMEOUT, 10);
		// Exchange or refresh a token
		if ($method === 'oauth') {
			$headers = array('Content-Type: application/x-www-form-urlencoded');
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
		// Call an API method
		} else {
			$url = self::API_ENDPOINT . '/' . $method . '.json';
			$params['grant_type'] = 'client_credentials';
			$headers = array('Content-Type: application/json; charset=utf-8');
			if (isset($this->auth_details['access_token'])) { // Authenticating using OAuth
				$headers[] = 'Authorization: Bearer ' . $this->auth_details['access_token'];
			} else if (isset($this->auth_details['api_key'])) { // Authenticating using an API key
				curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
				curl_setopt($ch, CURLOPT_USERPWD, $this->auth_details['api_key'] . ':nopass');
			}
			curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
		}
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		$response = curl_exec($ch);
		if (curl_error($ch)) {
			trigger_error('API call to ' . $url . ' failed: ' . curl_error($ch), E_USER_ERROR);
			return false;
		}
		curl_close($ch);
		return $response ? json_decode($response) : false;
	}
122721
public function request($method, $url, $params = null, $headers = [])
    {
        $headers = array_merge(self::defaultHeaders(), $headers);
        $absUrl = $this->apiBase . $url;
        return $this->httpClient()->request($method, $absUrl, $params, $headers);
    }