public function execute(Request $request, Response $response)
    {
      // Open curl handler
      $handle = curl_init();

      // Set header callback
      curl_setopt($handle, CURLOPT_HEADERFUNCTION, array(&$response, 'header'));

      // Do not reuse connection
      curl_setopt($handle, CURLOPT_FORBID_REUSE, 1);
      curl_setopt($handle, CURLOPT_FRESH_CONNECT, 1);

      // Clear default "Expect: 100-continue" header
      //curl_setopt($handle, CURLOPT_HTTPHEADER, array('Expect:'));

      // Set custom headers
      if($request->hasHeaders())
      {
        curl_setopt($handle, CURLOPT_HEADER, 0);
        curl_setopt($handle, CURLOPT_HTTPHEADER, $request->getHeaders());
      }

      // Set authentication if needed
      if($request->hasUsername() && $request->hasPassword())
      {
        curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($handle, CURLOPT_USERPWD, $request->getUsername() . ':' . $request->getPassword());
      }

      // Set timeout
      if($request->hasTimeout())
        curl_setopt($handle, CURLOPT_TIMEOUT, $request->getTimeout());

      // Set curl options
      curl_setopt($handle, CURLOPT_URL, $request->getUrl());
      curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

      curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
      //curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0);

      curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1);

      // Get method
      $method = $request->getMethod();

      if(!method_exists($this, strtolower($method)))
        throw new Exception(__METHOD__ . '; Request method "' .$method . '" not supported');

      // Call request method handler
      call_user_func(array($this, strtolower($method)),  $handle, $request, $response);

      // Execute curl request
      curl_exec($handle);

      // Get info
      $info = curl_getinfo($handle);

      // Set info
      $response->setInfo($info);

      // Close curl handler
      if(!is_null($handle) && is_resource($handle))
        curl_close($handle);
    }
public function execute(Request $request, Response $response)
    {
      // Open curl handler
      $handle = curl_init();

      // Set header callback
      curl_setopt($handle, CURLOPT_HEADERFUNCTION, array(&$response, 'header'));

      // Do not reuse connection
      curl_setopt($handle, CURLOPT_FORBID_REUSE, 1);
      curl_setopt($handle, CURLOPT_FRESH_CONNECT, 1);

      // Clear default "Expect: 100-continue" header
      //curl_setopt($handle, CURLOPT_HTTPHEADER, array('Expect:'));

      // Set custom headers
      if($request->hasHeaders())
      {
        curl_setopt($handle, CURLOPT_HEADER, 0);
        curl_setopt($handle, CURLOPT_HTTPHEADER, $request->getHeaders());
      }

      // Set authentication if needed
      if($request->hasUsername() && $request->hasPassword())
      {
        curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($handle, CURLOPT_USERPWD, $request->getUsername() . ':' . $request->getPassword());
      }

      // Set timeout
      if($request->hasTimeout())
        curl_setopt($handle, CURLOPT_TIMEOUT, $request->getTimeout());

      // Set curl options
      curl_setopt($handle, CURLOPT_URL, $request->getUrl());
      curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

      curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
      //curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0);

      curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1);

      // Get method
      $method = $request->getMethod();

      if(!method_exists($this, strtolower($method)))
        throw new Exception(__METHOD__ . '; Request method "' .$method . '" not supported');

      // Call request method handler
      call_user_func(array($this, strtolower($method)),  $handle, $request, $response);

      // Execute curl request
      curl_exec($handle);

      // Get info
      $info = curl_getinfo($handle);

      // Set info
      $response->setInfo($info);

      // Close curl handler
      if(!is_null($handle) && is_resource($handle))
        curl_close($handle);
    }
public function execute ( Request $ request , Response $ response ) { // Open curl handler $ handle = curl_init ( ) ; // Set header callback curl_setopt ( $ handle , CURLOPT_HEADERFUNCTION , array ( & $ response , 'header' ) ) ; // Do not reuse connection curl_setopt ( $ handle , CURLOPT_FORBID_REUSE , 1 ) ; curl_setopt ( $ handle , CURLOPT_FRESH_CONNECT , 1 ) ; // Clear default "Expect: 100-continue" header //curl_setopt($handle, CURLOPT_HTTPHEADER, array('Expect:')); // Set custom headers if ( $ request -> hasHeaders ( ) ) { curl_setopt ( $ handle , CURLOPT_HEADER , 0 ) ; curl_setopt ( $ handle , CURLOPT_HTTPHEADER , $ request -> getHeaders ( ) ) ; } // Set authentication if needed if ( $ request -> hasUsername ( ) && $ request -> hasPassword ( ) ) { curl_setopt ( $ handle , CURLOPT_HTTPAUTH , CURLAUTH_BASIC ) ; curl_setopt ( $ handle , CURLOPT_USERPWD , $ request -> getUsername ( ) . ':' . $ request -> getPassword ( ) ) ; } // Set timeout if ( $ request -> hasTimeout ( ) ) curl_setopt ( $ handle , CURLOPT_TIMEOUT , $ request -> getTimeout ( ) ) ; // Set curl options curl_setopt ( $ handle , CURLOPT_URL , $ request -> getUrl ( ) ) ; curl_setopt ( $ handle , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ handle , CURLOPT_SSL_VERIFYPEER , FALSE ) ; //curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt ( $ handle , CURLOPT_SSL_VERIFYHOST , 0 ) ; curl_setopt ( $ handle , CURLOPT_FOLLOWLOCATION , 1 ) ; // Get method $ method = $ request -> getMethod ( ) ; if ( ! method_exists ( $ this , strtolower ( $ method ) ) ) throw new Exception ( __METHOD__ . '; Request method "' . $ method . '" not supported' ) ; // Call request method handler call_user_func ( array ( $ this , strtolower ( $ method ) ) , $ handle , $ request , $ response ) ; // Execute curl request curl_exec ( $ handle ) ; // Get info $ info = curl_getinfo ( $ handle ) ; // Set info $ response -> setInfo ( $ info ) ; // Close curl handler if ( ! is_null ( $ handle ) && is_resource ( $ handle ) ) curl_close ( $ handle ) ; }
Do rest call

@param Request $request
@param Request $response
@throws Exception
Do rest call