public function sendRequest(RequestInterface $request): ResponseInterface
    {
        $responseBuilder = $this->createResponseBuilder();
        $requestOptions = $this->prepareRequestOptions($request, $responseBuilder);

        if (is_resource($this->handle)) {
            curl_reset($this->handle);
        } else {
            $this->handle = curl_init();
        }

        curl_setopt_array($this->handle, $requestOptions);
        curl_exec($this->handle);

        $errno = curl_errno($this->handle);
        switch ($errno) {
            case CURLE_OK:
                // All OK, no actions needed.
                break;
            case CURLE_COULDNT_RESOLVE_PROXY:
            case CURLE_COULDNT_RESOLVE_HOST:
            case CURLE_COULDNT_CONNECT:
            case CURLE_OPERATION_TIMEOUTED:
            case CURLE_SSL_CONNECT_ERROR:
                throw new Exception\NetworkException(curl_error($this->handle), $request);
            default:
                throw new Exception\RequestException(curl_error($this->handle), $request);
        }

        $response = $responseBuilder->getResponse();
        $response->getBody()->seek(0);

        return $response;
    }
public function sendRequest(RequestInterface $request): ResponseInterface
    {
        $responseBuilder = $this->createResponseBuilder();
        $requestOptions = $this->prepareRequestOptions($request, $responseBuilder);

        if (is_resource($this->handle)) {
            curl_reset($this->handle);
        } else {
            $this->handle = curl_init();
        }

        curl_setopt_array($this->handle, $requestOptions);
        curl_exec($this->handle);

        $errno = curl_errno($this->handle);
        switch ($errno) {
            case CURLE_OK:
                // All OK, no actions needed.
                break;
            case CURLE_COULDNT_RESOLVE_PROXY:
            case CURLE_COULDNT_RESOLVE_HOST:
            case CURLE_COULDNT_CONNECT:
            case CURLE_OPERATION_TIMEOUTED:
            case CURLE_SSL_CONNECT_ERROR:
                throw new Exception\NetworkException(curl_error($this->handle), $request);
            default:
                throw new Exception\RequestException(curl_error($this->handle), $request);
        }

        $response = $responseBuilder->getResponse();
        $response->getBody()->seek(0);

        return $response;
    }
public function sendRequest ( RequestInterface $ request ) : ResponseInterface { $ responseBuilder = $ this -> createResponseBuilder ( ) ; $ requestOptions = $ this -> prepareRequestOptions ( $ request , $ responseBuilder ) ; if ( is_resource ( $ this -> handle ) ) { curl_reset ( $ this -> handle ) ; } else { $ this -> handle = curl_init ( ) ; } curl_setopt_array ( $ this -> handle , $ requestOptions ) ; curl_exec ( $ this -> handle ) ; $ errno = curl_errno ( $ this -> handle ) ; switch ( $ errno ) { case CURLE_OK : // All OK, no actions needed. break ; case CURLE_COULDNT_RESOLVE_PROXY : case CURLE_COULDNT_RESOLVE_HOST : case CURLE_COULDNT_CONNECT : case CURLE_OPERATION_TIMEOUTED : case CURLE_SSL_CONNECT_ERROR : throw new Exception \ NetworkException ( curl_error ( $ this -> handle ) , $ request ) ; default : throw new Exception \ RequestException ( curl_error ( $ this -> handle ) , $ request ) ; } $ response = $ responseBuilder -> getResponse ( ) ; $ response -> getBody ( ) -> seek ( 0 ) ; return $ response ; }
Sends a PSR-7 request and returns a PSR-7 response.

@param RequestInterface $request

@return ResponseInterface

@throws \InvalidArgumentException  For invalid header names or values.
@throws \RuntimeException          If creating the body stream fails.
@throws Exception\NetworkException In case of network problems.
@throws Exception\RequestException On invalid request.

@since 1.6 \UnexpectedValueException replaced with RequestException
@since 1.6 Throw NetworkException on network errors
@since 1.0
Sends a PSR - 7 request and returns a PSR - 7 response .