Perform curl request

@return mixed
960429
protected function getRecaptchaResult()
    {
        $response = $this->guzzle->request(
            'POST',
            'https://www.google.com/recaptcha/api/siteverify',
            [
                'timeout'   => 2.0,
                'query'     => [
                    'secret'    => $this->config->get('antispam.recaptcha.secret', ''),
                    'response'  => $this->request->get('g-recaptcha-response', ''),
                    'remoteip'  => $this->request->getClientIp(),
                ],
            ]
        );

        return json_decode($response->getBody()->getContents());
    }
607147
public function exec()
    {
        $this->build();

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

        if(curl_errno($this->ch))
        {
            throw new CurlError(curl_error($this->ch));
        }

        curl_close($this->ch);

        return $data;
    }
353820
public function request()
    {
        $reqUrl = sprintf('%s?APIKEY=%s', self::END_POINT_URL, rawurlencode($this->apikey));
        $reqBody = json_encode($this->getParameter()->makeParameter());

        $curl = new Curl();
        $curl->setHeader('Content-Type', 'application/json; charset=UTF-8');
        $ret = $curl->post($reqUrl, $reqBody);
        if ($curl->error) {
            trigger_error('docomo dialogue: Error ' . $curl->errorCode . ': ' . $curl->errorMessage, E_USER_WARNING);
            return false;
        }
        return new Response($ret);
    }
988580
public function request( $url, $payload = array(), $curlOptions = array(), $method = Curl::Get )
    {
        $_response = null;

        if ( $this->_hostPort )
        {
            Curl::setHostPort( $this->_hostPort );
        }

        if ( $this->_userName )
        {
            Curl::setUserName( $this->_userName );

            if ( $this->_password )
            {
                Curl::setPassword( $this->_password );
            }
        }

        return Curl::request( $method, $url, $payload, $curlOptions );
    }
785434
public function getRequest()
    {
        $path = $_SERVER['REQUEST_URI'];
    
        //remove ? url queries
        if (strpos($path, '?') !== false) {
            list($path, $tmp) = explode('?', $path, 2);
        }

        $array = explode('/', $path);
        
        $path = array(
            'string' => $path,
            'array' => $array);
            
        //set the request
        return $this('registry')
            ->set('method', $_SERVER['REQUEST_METHOD'])
            ->set('query', $_SERVER['QUERY_STRING'])
            ->set('body', file_get_contents('php://input'))
            ->set('server', $_SERVER)
            ->set('cookie', $_COOKIE)
            ->set('get', $_GET)
            ->set('post', $_POST)
            ->set('files', $_FILES)
            ->set('path', $path);
    }
342224
private function curlit() {
    $this->response['raw'] = '';

    // method handling
    switch ($this->method) {
      case 'POST':
        break;
      default:
        // GET, DELETE request so convert the parameters to a querystring
        if ( ! empty($this->request_params)) {
          foreach ($this->request_params as $k => $v) {
            // Multipart params haven't been encoded yet.
            // Not sure why you would do a multipart GET but anyway, here's the support for it
            if ($this->config['multipart']) {
              $params[] = $this->safe_encode($k) . '=' . $this->safe_encode($v);
            } else {
              $params[] = $k . '=' . $v;
            }
          }
          $qs = implode('&', $params);
          $this->url = strlen($qs) > 0 ? $this->url . '?' . $qs : $this->url;
          $this->request_params = array();
        }
        break;
    }

    // configure curl
    $c = curl_init();
    curl_setopt_array($c, array(
      CURLOPT_USERAGENT      => $this->config['user_agent'],
      CURLOPT_CONNECTTIMEOUT => $this->config['curl_connecttimeout'],
      CURLOPT_TIMEOUT        => $this->config['curl_timeout'],
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_SSL_VERIFYPEER => $this->config['curl_ssl_verifypeer'],
      CURLOPT_SSL_VERIFYHOST => $this->config['curl_ssl_verifyhost'],

      CURLOPT_FOLLOWLOCATION => $this->config['curl_followlocation'],
      CURLOPT_PROXY          => $this->config['curl_proxy'],
      CURLOPT_ENCODING       => $this->config['curl_encoding'],
      CURLOPT_URL            => $this->url,
      // process the headers
      CURLOPT_HEADERFUNCTION => array($this, 'curlHeader'),
      CURLOPT_HEADER         => false,
      CURLINFO_HEADER_OUT    => true,
    ));

    if ($this->config['curl_cainfo'] !== false)
      curl_setopt($c, CURLOPT_CAINFO, $this->config['curl_cainfo']);

    if ($this->config['curl_capath'] !== false)
      curl_setopt($c, CURLOPT_CAPATH, $this->config['curl_capath']);

    if ($this->config['curl_proxyuserpwd'] !== false)
      curl_setopt($c, CURLOPT_PROXYUSERPWD, $this->config['curl_proxyuserpwd']);

    if ($this->config['is_streaming']) {
      // process the body
      $this->response['content-length'] = 0;
      curl_setopt($c, CURLOPT_TIMEOUT, 0);
      curl_setopt($c, CURLOPT_WRITEFUNCTION, array($this, 'curlWrite'));
    }

    switch ($this->method) {
      case 'GET':
        break;
      case 'POST':
        curl_setopt($c, CURLOPT_POST, true);
        break;
      default:
        curl_setopt($c, CURLOPT_CUSTOMREQUEST, $this->method);
    }

    if ( ! empty($this->request_params) ) {
      // if not doing multipart we need to implode the parameters
      if ( ! $this->config['multipart'] ) {
        foreach ($this->request_params as $k => $v) {
          $ps[] = "{$k}={$v}";
        }
        $this->request_params = implode('&', $ps);
      }
      curl_setopt($c, CURLOPT_POSTFIELDS, $this->request_params);
    } else {
      // CURL will not set the content-length  (or set it to -1) when there is no data, which breaks Twitter
      // override this and set the length to 0 in that case.
      $this->headers['Content-Type'] = '';
      $this->headers['Content-Length'] = '0';
    }

    // CURL defaults to setting this to Expect: 100-Continue which Twitter rejects
    $this->headers['Expect'] = '';

    if ( ! empty($this->headers)) {
      foreach ($this->headers as $k => $v) {
        $headers[] = trim($k . ': ' . $v);
      }
      curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
    }

    if (isset($this->config['prevent_request']) && true == $this->config['prevent_request'])
      return;

    // do it!
    $response = curl_exec($c);
    $code = curl_getinfo($c, CURLINFO_HTTP_CODE);
    $info = curl_getinfo($c);
    $error = curl_error($c);
    $errno = curl_errno($c);
    curl_close($c);

    // store the response
    $this->response['code'] = $code;
    $this->response['response'] = $response;
    $this->response['info'] = $info;
    $this->response['error'] = $error;
    $this->response['errno'] = $errno;

    if (!isset($this->response['raw'])) {
      $this->response['raw'] = '';
    }
    $this->response['raw'] .= $response;

    return $code;
  }
61509
private function execute() {
        $curlResponse = curl_exec($this->curl);

        $error = $this->getError();
        if (!empty($error)) {
            return $this->curlException($error['error'], $error['error_no']);
        }

        return $curlResponse;
    }
902153
protected function postRequest()
    {
        $response = $this->client->post($this->buildUrl(),
            [
                'auth'    => $this->getAuth(),
                'json'    => $this->getBody(),
                'headers' => [
                    'Accept' => 'application/json',
                ],
            ]);

        if ($response->getStatusCode() != 201 && $response->getStatusCode() != 200) {
            throw new \Exception('Unable to request from API. HTTP Error: '.$response->getStatusCode());
        }

        return $response;
    }
1346272
public function send()
    {

        $this->ok = false;
// Try using curl if available
        if (function_exists('curl_init')) {
            $resp = '';
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $this->url);
            if (!empty($this->requestHeaders)) {
                curl_setopt($ch, CURLOPT_HTTPHEADER, $this->requestHeaders);
            } else {
                curl_setopt($ch, CURLOPT_HEADER, 0);
            }
            if ($this->method === 'POST') {
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request);
            } else if ($this->method !== 'GET') {
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
                if (!is_null($this->request)) {
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request);
                }
            }
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLINFO_HEADER_OUT, true);
            curl_setopt($ch, CURLOPT_HEADER, true);
            $chResp = curl_exec($ch);
            $this->ok = $chResp !== false;
            if ($this->ok) {
                $chResp = str_replace("\r\n", "\n", $chResp);
                $chRespSplit = explode("\n\n", $chResp, 2);
                if ((count($chRespSplit) > 1) && (substr($chRespSplit[1], 0, 5) === 'HTTP/')) {
                    $chRespSplit = explode("\n\n", $chRespSplit[1], 2);
                }
                $this->responseHeaders = $chRespSplit[0];
                $resp = $chRespSplit[1];
                $this->status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                $this->ok = $this->status < 400;
                if (!$this->ok) {
                    $this->error = curl_error($ch);
                }
            }
            $this->requestHeaders = str_replace("\r\n", "\n", curl_getinfo($ch, CURLINFO_HEADER_OUT));
            curl_close($ch);
            $this->response = $resp;
        } else {
// Try using fopen if curl was not available
            $opts = array('method' => $this->method,
                          'content' => $this->request
                         );
            if (!empty($this->requestHeaders)) {
                $opts['header'] = $this->requestHeaders;
            }
            try {
                $ctx = stream_context_create(array('http' => $opts));
                $fp = @fopen($this->url, 'rb', false, $ctx);
                if ($fp) {
                    $resp = @stream_get_contents($fp);
                    $this->ok = $resp !== false;
                }
            } catch (\Exception $e) {
                $this->ok = false;
            }
        }

        return $this->ok;

    }
711279
protected function execute()
    {
        if ($this->url === null) {
            throw new CurlException('You have to provide an URL for the CurlRequest');
        }

        $ch = curl_init($this->url);
        curl_setopt_array($ch, $this->options);

        $this->content = curl_exec($ch);
        $this->infos   = curl_getinfo($ch);
        $this->error   = curl_error($ch);

        curl_close($ch);

        return $this->content;
    }
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;
	}
1290729
public function send() {

            if(!extension_loaded('curl')) throw new Exception('CURL library not loaded!');

            // cleanup any response
            $this->response = array();
 
            // array of curl handles
            $curly = array();
            
            // data to be returned
            $result = array();
            
            // multi handle
            $mh = curl_multi_init();
            
            // make sure request is array
            if (is_string($this->request)) $this->request = array($this->request);
           
            // loop through data request and create curl handles then add them to the multi-handle
            foreach ($this->request as $id => $d) {
                $curly[$id] = curl_init();
                $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
                curl_setopt($curly[$id], CURLOPT_URL, $url);
                if ($this->httpStatusOnly) curl_setopt($curly[$id], CURLOPT_NOBODY, 1);
           
                // contains data to post?
                if (is_array($d)) {
                    if (!empty($d['post'])) {
                        curl_setopt($curly[$id], CURLOPT_POST,       1);
                        if ($this->encoded && is_array($d['post'])) {
                            curl_setopt($curly[$id], CURLOPT_POSTFIELDS, http_build_query($d['post']));
                        } else {
                            curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
                        }
                    }
                }
           
                // set options?
                if (!empty($this->options)) {
                    curl_setopt_array($curly[$id], $this->options);
                } else {
                    curl_setopt($curly[$id], CURLOPT_HEADER,         0);
                    curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
                }

                // activate curl response message
                if($this->httpInfo === 'detail'){
                    if (empty($this->options[CURLOPT_FAILONERROR]) || (!empty($this->options[CURLOPT_FAILONERROR]) && $this->options[CURLOPT_FAILONERROR] == false)){
                        curl_setopt($curly[$id], CURLOPT_FAILONERROR, 1);
                    }
                }
           
                curl_multi_add_handle($mh, $curly[$id]);
            }
           
            // execute the handles
            $running = null;
            do {
                $mrc =curl_multi_exec($mh, $running);
            } while($mrc == CURLM_CALL_MULTI_PERFORM);

            // perform multi select
            while ($running && $mrc == CURLM_OK) {
                if (curl_multi_select($mh) == -1) {
                    // delay time for cpu take a rest in every 10ms
                    usleep($this->delayTime);
                }
            
                do {
                    $mrc = curl_multi_exec($mh, $running);
                } while ($mrc == CURLM_CALL_MULTI_PERFORM);
            }
           
            // get content and remove handles
            foreach($curly as $id => $c) {
                if ($this->httpStatusOnly){
                    $result[$id] = curl_getinfo($c, CURLINFO_HTTP_CODE);
                } else {
                    if ($this->httpInfo){
                        $curl_errno = curl_errno($c);
                        if($this->httpInfo === 'detail'){
                            $http_code = curl_getinfo($c, CURLINFO_HTTP_CODE);
                            $curl_error = curl_error($c);
                            $result[$id] = [
                                'code' => $http_code,
                                'info' => [
                                    'url' => curl_getinfo($c, CURLINFO_EFFECTIVE_URL),
                                    'content_type' => curl_getinfo($c, CURLINFO_CONTENT_TYPE),
                                    'content_length' => curl_getinfo($c, CURLINFO_CONTENT_LENGTH_DOWNLOAD),
                                    'total_time' => curl_getinfo($c, CURLINFO_TOTAL_TIME),
                                    'debug' => 'CURLcode ['.$curl_errno.']: '.$this->getCurlCode($curl_errno),
                                    'message' => (($curl_error)?$curl_error:(($http_code == 0)?'The requested URL returned error: Unknown':'Request URL finished'))
                                ],
                                'response' => curl_multi_getcontent($c)
                            ];
                        } else {
                            $result[$id] = [
                                'code' => curl_getinfo($c, CURLINFO_HTTP_CODE),
                                'debug' => $this->getCurlCode($curl_errno),
                                'response' => curl_multi_getcontent($c)
                            ];
                        }
                    } else {
                        $result[$id] = curl_multi_getcontent($c);
                    }
                }
                curl_multi_remove_handle($mh, $c);
            }
           
            // close when all is done
            curl_multi_close($mh);
            if (count($result) <= 1) {
                $this->response = $result[0];
            } else {
                $this->response = $result;
            }
            return $this;
        }
232045
public function request($args) {
		$c = curl_init();
		
		curl_setopt($c, CURLOPT_TIMEOUT, 4);
		curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($c, CURLOPT_USERAGENT, 'groupmeClient/0.1');
		curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($c, CURLOPT_CUSTOMREQUEST, $args['method']);
		
		$curlurl = $this->url . $args['url'] . $this->buildQueryString($args['query']);
		curl_setopt($c, CURLOPT_URL, $curlurl );
		
		if($args['method'] == "POST"){
			if ( isset($args['payload']) ) {
				$payload = "";
				if ( isset($args['payload']['file']) ) {
					$payload = $args['payload'];
				}
				else {
					$payload = json_encode($args['payload']);
					curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
				}
								
				curl_setopt($c, CURLOPT_POSTFIELDS, $payload );
			}
		}
		$info = curl_getinfo($c);
		$response = curl_exec($c);
		curl_close($c);
		return $response;
	}
450774
private function RunRequest()
    {
        $result = curl_exec($this->_curlHandle);
        if ($result === false && curl_errno($this->_curlHandle) != 0) {
            $this->logger->error("cURL error: " . curl_error($this->_curlHandle));
            throw new Exception('cURL error: ' . curl_error($this->_curlHandle));
        }

        $response = new HttpResponse();
        $response->ResponseCode = (int) curl_getinfo($this->_curlHandle, CURLINFO_HTTP_CODE);

        curl_close($this->_curlHandle);

        $explode = explode("\r\n\r\n", $result);

        // multiple query (follow redirect) take only the last request
        $explode = array_slice($explode, sizeof($explode) - 2, 2);

        $response->Headers = explode("\n", implode($explode));
        $response->Body = array_pop($explode);

        return $response;
    }
556083
public function execute()
    {
        $this->setOptions();

        $response = $this->parseResponse($this->curlExecute());

        $this->close();

        return $response;
    }
1190538
protected function doCurl()
    {
        $response = curl_exec($this->curl);

        if (curl_errno($this->curl)) {
            throw new \Exception(curl_error($this->curl), 1);
        }

        $curlInfo = curl_getinfo($this->curl);

        $results = array(
            'curl_info' => $curlInfo,
            'response' => $response,
        );

        return $results;
    }
1257961
protected function curlExecute()
    {
        $response = curl_exec($this->getResource());

        $curlErrorNumber = $this->getErrorNumber();
        if ($curlErrorNumber) {
            /**
             * @var \OxidEsales\PayPalModule\Core\Exception\PayPalException $exception
             */
            $exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalException::class, 'Curl error: ' . $curlErrorNumber);
            throw $exception;
        }

        return $response;
    }