src/Session.php
public function sendHttpRequest(array $requestData, $method = 'POST')
    {
        // Perform re-login if required.
        if ('getchallenge' !== $requestData[ 'operation' ] && time() > $this->serviceExpireTime) {
            $this->login($this->userName, $this->accessKey);
        }

        $requestData[ 'sessionName' ] = $this->sessionName;
        
        try {
            switch ($method) {
                case 'GET':
                    $response = $this->httpClient->get($this->wsBaseURL, [ 'query' => $requestData, 'timeout' => $this->requestTimeout ]);
                    break;
                case 'POST':
                    $response = $this->httpClient->post($this->wsBaseURL, [ 'form_params' => $requestData, 'timeout' => $this->requestTimeout ]);
                    break;
                default:
                    throw new WSException("Unsupported request type {$method}");
            }
        } catch (RequestException $ex) {
            $urlFailed = $this->httpClient->getConfig('base_uri').$this->wsBaseURL;
            throw new WSException(
                sprintf('Failed to execute %s call on "%s" URL', $method, $urlFailed),
                'FAILED_SENDING_REQUEST',
                $ex
            );
        }

        $jsonRaw = $response->getBody();
        $jsonObj = json_decode($jsonRaw, true);

        $result = (is_array($jsonObj) && !self::checkForError($jsonObj))
            ? $jsonObj[ 'result' ]
            : null;
        return $result;
    }
public function sendHttpRequest(array $requestData, $method = 'POST')
    {
        // Perform re-login if required.
        if ('getchallenge' !== $requestData[ 'operation' ] && time() > $this->serviceExpireTime) {
            $this->login($this->userName, $this->accessKey);
        }

        $requestData[ 'sessionName' ] = $this->sessionName;
        
        try {
            switch ($method) {
                case 'GET':
                    $response = $this->httpClient->get($this->wsBaseURL, [ 'query' => $requestData, 'timeout' => $this->requestTimeout ]);
                    break;
                case 'POST':
                    $response = $this->httpClient->post($this->wsBaseURL, [ 'form_params' => $requestData, 'timeout' => $this->requestTimeout ]);
                    break;
                default:
                    throw new WSException("Unsupported request type {$method}");
            }
        } catch (RequestException $ex) {
            $urlFailed = $this->httpClient->getConfig('base_uri').$this->wsBaseURL;
            throw new WSException(
                sprintf('Failed to execute %s call on "%s" URL', $method, $urlFailed),
                'FAILED_SENDING_REQUEST',
                $ex
            );
        }

        $jsonRaw = $response->getBody();
        $jsonObj = json_decode($jsonRaw, true);

        $result = (is_array($jsonObj) && !self::checkForError($jsonObj))
            ? $jsonObj[ 'result' ]
            : null;
        return $result;
    }
public function sendHttpRequest ( array $ requestData , $ method = 'POST' ) { // Perform re-login if required. if ( 'getchallenge' !== $ requestData [ 'operation' ] && time ( ) > $ this -> serviceExpireTime ) { $ this -> login ( $ this -> userName , $ this -> accessKey ) ; } $ requestData [ 'sessionName' ] = $ this -> sessionName ; try { switch ( $ method ) { case 'GET' : $ response = $ this -> httpClient -> get ( $ this -> wsBaseURL , [ 'query' => $ requestData , 'timeout' => $ this -> requestTimeout ] ) ; break ; case 'POST' : $ response = $ this -> httpClient -> post ( $ this -> wsBaseURL , [ 'form_params' => $ requestData , 'timeout' => $ this -> requestTimeout ] ) ; break ; default : throw new WSException ( "Unsupported request type {$method}" ) ; } } catch ( RequestException $ ex ) { $ urlFailed = $ this -> httpClient -> getConfig ( 'base_uri' ) . $ this -> wsBaseURL ; throw new WSException ( sprintf ( 'Failed to execute %s call on "%s" URL' , $ method , $ urlFailed ) , 'FAILED_SENDING_REQUEST' , $ ex ) ; } $ jsonRaw = $ response -> getBody ( ) ; $ jsonObj = json_decode ( $ jsonRaw , true ) ; $ result = ( is_array ( $ jsonObj ) && ! self :: checkForError ( $ jsonObj ) ) ? $ jsonObj [ 'result' ] : null ; return $ result ; }
Sends HTTP request to VTiger web service API endpoint
@access private
@param  array $requestData HTTP request data
@param  string $method HTTP request method (GET, POST etc)
@return array Returns request result object (null in case of failure)
Sends HTTP request to VTiger web service API endpoint