Execute the curl call.

@throws DownloaderException
@return mixed
547869
private function download($uri)
    {
        curl_setopt($this->handle, CURLOPT_URL, $uri);
        $result = curl_exec($this->handle);

        $curl_info = curl_getinfo($this->handle);
        if ($curl_info['http_code'] >= 400) {
            throw new DownloaderException(
                sprintf(
                    "Failed to download '%s'. HTTP Code: %d",
                    $uri,
                    $curl_info['http_code']
                )
            );
        }
        return $result;
    }
924382
private function executeCurl()
    {
        if ($this->initCurl()){
            $this->configureCurl();
            $this->CurlResponse = curl_exec($this->CurlRequest);
            $this->checkForError();
            return TRUE;
        }
        return FALSE;
    }
738467
public function start()
    {
        if ($this->isStarted) {
            return;
        }

        foreach ($this->curls as $ch) {
            $this->initHandle($ch);
        }

        $this->isStarted = true;

        do {
            curl_multi_select($this->multiCurl);
            curl_multi_exec($this->multiCurl, $active);

            while (!($info_array = curl_multi_info_read($this->multiCurl)) === false) {
                if ($info_array['msg'] === CURLMSG_DONE) {
                    foreach ($this->curls as $key => $ch) {
                        if ($ch->curl === $info_array['handle']) {
                            $ch->curlErrorCode = $info_array['result'];
                            $ch->exec($ch->curl);
                            curl_multi_remove_handle($this->multiCurl, $ch->curl);
                            unset($this->curls[$key]);

                            // Close open file handles and reset the curl instance.
                            if (!($ch->fileHandle === null)) {
                                $ch->downloadComplete($ch->fileHandle);
                            }
                            break;
                        }
                    }
                }
            }

            if (!$active) {
                $active = count($this->curls);
            }
        } while ($active > 0);

        $this->isStarted = false;
    }
1108958
public function execute()
    {
        $code = $this->getRequest()->getParam('code', false);
        $userId = $this->getRequest()->getParam('state');
        //load admin user
        $adminUser = $this->adminUser->create();
        $this->userResource->load($adminUser, $userId);
        //app code and admin user must be present
        if ($code && $adminUser->getId()) {
            $clientId = $this->scopeConfig->getValue(
                \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_ID
            );
            $clientSecret = $this->scopeConfig->getValue(
                \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID
            );
            //callback uri if not set custom
            $redirectUri = $this->storeManager->getStore()
                ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, true);
            $redirectUri .= 'connector/email/callback';

            $data = 'client_id=' . $clientId .
                '&client_secret=' . $clientSecret .
                '&redirect_uri=' . $redirectUri .
                '&grant_type=authorization_code' .
                '&code=' . $code;

            //callback url
            $url = $this->config->getTokenUrl();

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 60);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);

            $response = json_decode(curl_exec($ch));

            if ($response === false) {
                $this->helper->error('Error Number: ' . curl_errno($ch), []);
            }
            if (isset($response->error)) {
                $this->helper->error('OAUTH failed ' . $response->error, []);
            } elseif (isset($response->refresh_token)) {
                //save the refresh token to the admin user
                $adminUser->setRefreshToken(
                    $this->helper->encryptor->encrypt($response->refresh_token)
                );

                $this->userResource->save($adminUser);
            }

            //redirect to automation index page
            return $this->_redirect($this->adminHelper->getUrl('dotdigitalgroup_email/studio'));
        }

        return $this->resultPageFactory->create()
            ->setStatusHeader(404, '1.1', 'Not Found')
            ->setHeader('Status', '404 File not found');
    }
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;
	}
490304
public function execute()
    {
        $ch = curl_init();
        $this->setAuth($ch);
        try {
            switch (strtoupper($this->verb)) {
                case 'GET':
                    $this->executeGet($ch);
                    break;
                case 'POST':
                    $this->executePost($ch);
                    break;
                case 'PUT':
                    $this->executePut($ch);
                    break;
                case 'DELETE':
                    $this->executeDelete($ch);
                    break;
                default:
                    throw new \InvalidArgumentException(
                        'Current verb (' . $this->verb
                        . ') is an invalid REST verb.'
                    );
            }
        } catch (\InvalidArgumentException $e) {
            curl_close($ch);
            throw $e;
        } catch (\Exception $e) {
            curl_close($ch);
            throw $e;
        }

        /*
         * check and debug api request total time
         */
        $this->processDebugApi();

        return $this->responseBody;
    }
244467
protected function process()
    {
        // Workaround for PHP Bug #61141.
        if (curl_multi_select($this->handle) === -1) {
            usleep(100);
        }

        do {
            $mrc = curl_multi_exec($this->handle, $active);
        } while ($mrc === CURLM_CALL_MULTI_PERFORM);

        return [$mrc, $active];
    }
1093091
private function curl()
    {
        if (!($this->curl instanceof cURL)) {
            $this->curl = new cURL();
        }

        if ($this->hasAuth()) {
            $this->curl->setCredentials($this->user, $this->pass);
        }

        if ($this->cookie && is_writeable(dirname($this->cookie))) {
            $this->curl->setCookieStorage($this->cookie);
        }

        return $this->curl->setTimeout($this->timeout);
    }
190168
protected function dispatch()
    {
        // Start processing the requests.
        list($mrc, $active) = $this->process();

        // Keep processing requests until we're done.
        while ($active and $mrc === CURLM_OK) {
            // Process the next request.
            list($mrc, $active) = $this->process();
        }

        // Throw an exception if something went wrong.
        if ($mrc !== CURLM_OK) {
            throw new CurlErrorException('cURL read error #'.$mrc);
        }
    }
108358
public function run()
    {
        $ch = curl_init();

        $query = '';
        if (!empty($this->parameters)) {
            $query = '?' . http_build_query ($this->parameters);
        }
        $this->query = $this->url . $query;
        if ($this->method == "GET") {
            curl_setopt($ch, CURLOPT_URL, $this->url . $query);
        } else {
            curl_setopt($ch, CURLOPT_URL, $this->url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
        }

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        foreach ($this->options as $key => $value)
        {
            curl_setopt($ch, $key, $value);
        }

        $this->response = curl_exec($ch);
        $this->curlInfo = curl_getinfo($ch);
        $this->curlError = curl_error($ch);
    }
759913
private function execute(&$http) {
      $result = curl_exec($http);

      if($result === false) {
        $error_code = curl_errno($http);
        $error_message = curl_error($http);

        curl_close($http);

        throw new CallFailed($error_code, $result, $error_message);
      } else {
        $status = (integer) curl_getinfo($http, CURLINFO_HTTP_CODE);

        curl_close($http);

        switch($status) {
          case 200:
            return $result;
          case 400:
          case 401:
          case 403:
          case 404:
          case 409:
          case 500:
          case 503:
          if(is_string($result) && substr($result, 0, 1) === '{') {
            throw new AppException($status, $result); // Known application exception
          } // if
        } // switch

        throw new CallFailed($status, $result); // Unknown exception
      } // if
    }
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;
        }
    }
834381
public function request() 
	{
		
		if(!$this->getResource()) {
			
			$this->exception("No curl resource was found", debug_backtrace());
		}

		$resource = $this->getResource(); 
		curl_setopt($resource, CURLOPT_URL, $this->getUri());
		//setting curl options
		$headers = $this->getHeaders();

		if(!empty($headers)) {
			
			curl_setopt($resource, CURLOPT_HTTPHEADER, $headers);

			//curl_setopt($resource, CURLOPT_HEADER, true);	
		}

		$method = $this->getMethod();

		$curlMethod = '';
		switch ($method) {
			case CheckoutApi_Client_Adapter_Constant::API_POST:
				$curlMethod =  CheckoutApi_Client_Adapter_Constant::API_POST;
				break;
			case CheckoutApi_Client_Adapter_Constant::API_GET:
				$curlMethod =  CheckoutApi_Client_Adapter_Constant::API_GET;

				break;
			case CheckoutApi_Client_Adapter_Constant::API_DELETE:
			    $curlMethod = CheckoutApi_Client_Adapter_Constant::API_DELETE;
			break;
            case CheckoutApi_Client_Adapter_Constant::API_PUT:
                $curlMethod = CheckoutApi_Client_Adapter_Constant::API_PUT;
            break;
			default :
				
				$this->exception("Method currently not supported", debug_backtrace());
			break;
		}

        if($curlMethod != CheckoutApi_Client_Adapter_Constant::API_GET) {
            curl_setopt($resource, CURLOPT_CUSTOMREQUEST, $curlMethod);
        }

//		curl_setopt($resource , $curlMethod, true);

		if($method == CheckoutApi_Client_Adapter_Constant::API_POST || $method == CheckoutApi_Client_Adapter_Constant::API_PUT  ) {
			curl_setopt($resource, CURLOPT_POSTFIELDS, $this->getPostedParam());
		}

		curl_setopt($resource, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($resource, CURLOPT_SSL_VERIFYPEER, false);


		$response = curl_exec($resource);
		$http_status = curl_getinfo($resource, CURLINFO_HTTP_CODE);

		if($http_status != 200 ) {
			$this->exception("An error has occurred while processing your transaction",
				array(
					'respond_code'=> $http_status,
					'curl_info' => curl_getinfo($resource),
					'respondBody'=>	$response,
					'postedParam' =>$this->getPostedParam(),
					'rawPostedParam' => $this->getRawpostedParam(),
					)
				);

		} elseif (curl_errno($resource)) {

			$info = curl_getinfo($resource);
			$this->exception("Curl issues ",$info);
		} 

 	    $this->setResource($resource);	
	    $this->setRespond($response);
		
		
		return $this;
	}
840987
protected function call()
    {
        // Check if the curl object is set
        if (!$this->isInit()) {
            // If it isn't, we do it right now
            $this->init();
        }

        $options = array();
        // Set basic authentication if enabled
        if ($this->authentication instanceof BasicAuthentication) {
            $options['auth'] = array(
                $this->authentication->getUsername(),
                $this->authentication->getPassword()
            );
        }

        // Set json
        if (($json = $this->getJson()) != null) {
            $options['json'] = $json;
            $this->setAccept('application/json');
        }

        if (($formParams = $this->getFormParams()) != null) {
            $options['body'] = $formParams;
            $this->setContentType('application/x-www-form-urlencoded');
        }

        $request = $this->getHttpClient()->createRequest(
            $this->getHttpMethod(),
            $this->getEndpoint(),
            array_merge(
                array('headers' => $this->getHeaders()),
                $options
            )
        );

        foreach ($this->getEndpointParameters() as $key => $value) {
            $request->getQuery()->set($key, $value);
        }

        if (($body = $this->getBody()) != null && (is_null($body))) {
            $request->setBody(Stream::factory($body));
        }

        $response = $this->getHttpClient()->send($request);

        $this->setHttpStatusCode($response->getStatusCode());

        $this->setData($response->json());
    }
1064851
public function send()
    {
        $this->open();

        if ($this->response === false) {
            throw new \Exception('Error: '.curl_errno($this->resource).' => '.curl_error($this->resource).'.');
        }
        // If the CURLOPT_RETURNTRANSFER option is set to true, get the response body and parse the headers.
        if (isset($this->options[CURLOPT_RETURNTRANSFER]) && ($this->options[CURLOPT_RETURNTRANSFER] == true)) {
            $headerSize = $this->getInfo(CURLINFO_HEADER_SIZE);
            if ($this->options[CURLOPT_HEADER]) {
                $this->responseHeader = substr($this->response, 0, $headerSize);
                $this->body = substr($this->response, $headerSize);
                $this->parseResponseHeaders();
            } else {
                $this->body = $this->response;
            }
        }

        if (array_key_exists('Content-Encoding', $this->responseHeaders)) {
            $this->decodeBody();
        }
    }
1197927
protected function exec()
    {
        //get response output and info
        $response = curl_exec($this->curl);
        $info     = curl_getinfo($this->curl);

        //if there is a curl error throw Exception
        if (curl_error($this->curl)) {
            //throw error
            throw new PipedriveHttpError('API call failed: ' . curl_error($this->curl));
        }
        //decode output
        $result = json_decode($response, true);

        //if http error throw exception
        if (floor($info['http_code'] / 100) >= 4) {
            //throw error
            throw new PipedriveApiError('API HTTP Error ' . $info['http_code'] . '. Message ' . $result['error']);
        }
        // return output
        return $result;
    }
817027
protected function executeCurl(array $options)
    {
        curl_setopt_array($this->curl, $options);

        $result = curl_exec($this->curl);
        self::curlValidate($this->curl, $result);
        if ($result === false) {
            throw new HttpException(curl_error($this->curl), curl_errno($this->curl));
        }

        return $result;
    }