Request

@param $parameters
@param string $method
@return mixed|\Psr\Http\Message\ResponseInterface
486403
protected function request($parameters, $method = 'GET')
    {
        $formParams = $this->getFormParams($parameters);

        if (!isset($formParams['api_key'])) {
            return null;
        }

        if ($method === 'POST') {
            // split params
            $response = $this->httpClient->request($method, Api::PATH_TO_API_SCRIPT, array(
                'query' => $this->getQueryParams($parameters),
                'form_params' => $formParams
            ));
        } else {
            // all params as query GET params
            $response = $this->httpClient->request($method, Api::PATH_TO_API_SCRIPT, array(
                'query' => array_merge($this->getQueryParams($parameters), $formParams),
            ));
        }

        return $response;
    }
131225
public function makeRequest($url, $method='GET', array $parameters=array())
    {
        //Set cURL options
        $this->curl_opts[CURLOPT_URL]        = $url;
        $this->curl_opts[CURLOPT_HTTPHEADER] = $this->headers->getHeaders();

	// Prepare Data
        if (!empty($parameters)) {
            switch($method) {
                case 'POST':
                    $this->curl_opts[CURLOPT_POST] = true;
                    $this->curl_opts[CURLOPT_POSTFIELDS] = Utilities::encodeUrlParam($parameters);
                    break;
                case 'PUT':
                    $file_handle = fopen($parameters, 'r');
                    $this->curl_opts[CURLOPT_PUT] = true;
                    $this->curl_opts[CURLOPT_INFILE] = $file_handle;
                    break;
                case 'DELETE':
                    $this->curl_opts[CURLOPT_CUSTOMREQUEST] = 'delete';
                    break;
            }
        }

        $response = $this->doCurlCall();

		if ($response['response'] === false) {
			throw new RequestException($response['errorMessage'], $response['errorNumber']);
		}

        return $response;
    }
175007
protected function newAPIRequest($method, $path, $parameters = [], $options = [])
    {
        $api_path = '/api/v1/' . $path;
        return $this->call($method, $api_path, $parameters, $options);
    }
1192955
private function buildRequestParams($method, $parameters = array()) {

        switch ($this->mode) {
            case 'client':
                $parameters['email'] = $this->email;
                $parameters['tkn']   = $this->token;
                $parameters['a']     = $method;
                break;
            case 'host':
                $parameters['host_key'] = $this->host_key;
                $parameters['act']      = $method;
                break;
        }


        return $parameters;
    }
183319
private function makeRequest($method, $uri, array $parameters = []) {
    try {
      $response = $this->request($method, $uri, $parameters);
      
      if (200 != $response->getStatusCode()) {
        throw new ActivenetClientException(sprintf('Got non 200 response code for the uri %s.', $uri));
      }

      if (!$body = $response->getBody()) {
        throw new ActivenetClientException(sprintf('Failed to get response body for the uri %s.', $uri));
      }

      if (!$contents = $body->getContents()) {
        throw new ActivenetClientException(sprintf('Failed to get body contents for the uri: %s.', $uri));
      }

      $object = json_decode($contents);

      // Check if object contains data.
      if (isset($object->body)) {
        return $object->body;
      }

      throw new ActivenetClientException(sprintf('Got unknown body name for method %s.', $method));
    }
    catch (\Exception $e) {
      throw new ActivenetClientException(sprintf('Failed to make a request for uri %s with message %s.', $uri, $e->getMessage()));
    }

  }
1078460
public function request($method, $path = null, $parameters = array())
    {
        if (null === $path) {
            $url = '/messages';
        } else {
            $url  = '/messages/'.$path;
        }

        return json_decode($this->requestRaw($method, $url, $parameters), true);
    }
310846
public function forward($uri, $method, array $parameters = [])
    {
        $request = Request::create($uri, $method, $parameters);

        return $this->handle($request, HttpKernelInterface::SUB_REQUEST);
    }
466828
public function callAction($method, $parameters)
    {
        $response = call_user_func_array([$this, $method], $parameters);

        if (is_null($response) && ! is_null($this->layout)) {
            $response = $this->layout;
        }

        return $response;
    }
978300
protected function callHelperMethod($method, $parameters)
    {
        return $this->app->make($this->helpers[$method], $parameters);
    }
43810
public function parameterize($method)
    {
        $parameterArray = array();
        switch ($method) {
            case 'create':
            case 'update':
                $parameterArray['email'] = $this->getEmail();
                $parameterArray['description'] = $this->getDescription();
                break;
            case 'getOne':
                $parameterArray['count'] = 1;
                $parameterArray['offset'] = 0;
                break;
            case 'getAll':
                $parameterArray = $this->getFilter();
                break;
            case 'delete':
                break;
        }

        return $parameterArray;
    }
773971
public function request($method = null)
    {
        if (! $this->uri instanceof Zend_Uri_Http) {
            /** @see Zend_Http_Client_Exception */

            throw new Zend_Http_Client_Exception('No valid URI has been passed to the client');
        }

        if ($method) {
            $this->setMethod($method);
        }
        $this->redirectCounter = 0;
        $response = null;

        // Make sure the adapter is loaded
        if ($this->adapter == null) {
            $this->setAdapter($this->config['adapter']);
        }

        // Send the first request. If redirected, continue.
        do {
            // Clone the URI and add the additional GET parameters to it
            $uri = clone $this->uri;
            if (! empty($this->paramsGet)) {
                $query = $uri->getQuery();
                   if (! empty($query)) {
                       $query .= '&';
                   }
                $query .= http_build_query($this->paramsGet, null, '&');
                if ($this->config['rfc3986_strict']) {
                    $query = str_replace('+', '%20', $query);
                }

                // @see ZF-11671 to unmask for some services to foo=val1&foo=val2
                if ($this->getUnmaskStatus()) {
                    if ($this->_queryBracketsEscaped) {
                        $query = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $query);
                    } else {
                        $query = preg_replace('/\\[(?:[0-9]|[1-9][0-9]+)\\]=/', '=', $query);
                    }
                }

                $uri->setQuery($query);
            }

            $body = $this->_prepareBody();
            $headers = $this->_prepareHeaders();

            // check that adapter supports streaming before using it
            if(is_resource($body) && !($this->adapter instanceof Zend_Http_Client_Adapter_Stream)) {
                /** @see Zend_Http_Client_Exception */

                throw new Zend_Http_Client_Exception('Adapter does not support streaming');
            }

            // Open the connection, send the request and read the response
            $this->adapter->connect($uri->getHost(), $uri->getPort(),
                ($uri->getScheme() == 'https' ? true : false));

            if($this->config['output_stream']) {
                if($this->adapter instanceof Zend_Http_Client_Adapter_Stream) {
                    $stream = $this->_openTempStream();
                    $this->adapter->setOutputStream($stream);
                } else {
                    /** @see Zend_Http_Client_Exception */

                    throw new Zend_Http_Client_Exception('Adapter does not support streaming');
                }
            }

            $this->last_request = $this->adapter->write($this->method,
                $uri, $this->config['httpversion'], $headers, $body);

            $response = $this->adapter->read();
            if (! $response) {
                /** @see Zend_Http_Client_Exception */

                throw new Zend_Http_Client_Exception('Unable to read response, or response is empty');
            }

            if($this->config['output_stream']) {
                $streamMetaData = stream_get_meta_data($stream);
                if ($streamMetaData['seekable']) {
                    rewind($stream);
                }
                // cleanup the adapter
                $this->adapter->setOutputStream(null);
                $response = Zend_Http_Response_Stream::fromStream($response, $stream);
                $response->setStreamName($this->_stream_name);
                if(!is_string($this->config['output_stream'])) {
                    // we used temp name, will need to clean up
                    $response->setCleanup(true);
                }
            } else {
                $response = Zend_Http_Response::fromString($response);
            }

            if ($this->config['storeresponse']) {
                $this->last_response = $response;
            }

            // Load cookies into cookie jar
            if (isset($this->cookiejar)) {
                $this->cookiejar->addCookiesFromResponse($response, $uri, $this->config['encodecookies']);
            }

            // If we got redirected, look for the Location header
            if ($response->isRedirect() && ($location = $response->getHeader('location'))) {

                // Avoid problems with buggy servers that add whitespace at the
                // end of some headers (See ZF-11283)
                $location = trim($location);

                // Check whether we send the exact same request again, or drop the parameters
                // and send a GET request
                if ($response->getStatus() == 303 ||
                   ((! $this->config['strictredirects']) && ($response->getStatus() == 302 ||
                       $response->getStatus() == 301))) {

                    $this->resetParameters();
                    $this->setMethod(self::GET);
                }

                // If we got a well formed absolute URI
                if (($scheme = substr($location, 0, 6)) && ($scheme == 'http:/' || $scheme == 'https:')) {
                    $this->setHeaders('host', null);
                    $this->setUri($location);

                } else {

                    // Split into path and query and set the query
                    if (strpos($location, '?') !== false) {
                        list($location, $query) = explode('?', $location, 2);
                    } else {
                        $query = '';
                    }
                    $this->uri->setQuery($query);

                    // Else, if we got just an absolute path, set it
                    if(strpos($location, '/') === 0) {
                        $this->uri->setPath($location);

                        // Else, assume we have a relative path
                    } else {
                        // Get the current path directory, removing any trailing slashes
                        $path = $this->uri->getPath();
                        $path = rtrim(substr($path, 0, strrpos($path, '/')), "/");
                        $this->uri->setPath($path . '/' . $location);
                    }
                }
                ++$this->redirectCounter;

            } else {
                // If we didn't get any location, stop redirecting
                break;
            }

        } while ($this->redirectCounter < $this->config['maxredirects']);

        return $response;
    }
1215426
public function command($method, array $parameters = [])
    {
        $start = microtime(true);

        $result = $this->client->{$method}(...$parameters);

        $time = round((microtime(true) - $start) * 1000, 2);

        if (isset($this->events)) {
            $this->event(new CommandExecuted($method, $parameters, $time, $this));
        }

        return $result;
    }
284410
public function withMethod($method)
    {
        $new = clone $this;

        if (!is_string($method) ||
            !preg_match('/^[!#$%&\'*+.^_`\|~0-9a-z-]+$/i', $method)
        ) {
            throw new InvalidArgumentException(sprintf(
                'Unsupported HTTP method "%s" provided',
                $method
            ));
        }
        $new->_environment['REQUEST_METHOD'] = $method;

        return $new;
    }
65056
protected function createRequest($client, $method, $uri = '', array $parameters = [])
    {
        /**
         * @see \JonnyW\PhantomJs\Http\Request
         **/
        $request = $client->getMessageFactory()->createRequest($uri, $method);
        $request->addHeader(
            'User-Agent',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0'
        );

        $request->addHeader(
            'Content-Type',
            'application/x-www-form-urlencoded'
        );

        if (isset($parameters['form_params'])) {
            $request->setRequestData($parameters['form_params']);
        }

        return $request;
    }
913464
public static function createRequest(string $method, $uri): RequestInterface
    {
        if (\is_string($uri)) {
            $uri = Uri::createFromString($uri);
        }

        return new Request($method, $uri);
    }
735540
public function prepare(string $method, array $parameters)
    {
        // Delete any empty key
        $parameters = $this->deleteEmptyKeys($parameters);

        // Add the API Key
        $parameters['apiKey'] = $this->flow->getCredentials()->apiKey;

        // Sort the parameters
        ksort($parameters);

        // Return the final data
        switch ($method) {
            case 'get':
                return $this->prepareGet($parameters);
            case 'post':
                return $this->preparePost($parameters);
            default:
                return null;
        }
    }
298195
public function call($method, $parameters)
    {
        try {
            $ch = curl_init($this->base_url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->encode($method, $parameters));
            curl_setopt($ch, CURLOPT_TIMEOUT, 600);

            $response = curl_exec($ch);

            if ($response === false) {
                $e = new TransportException(curl_error($ch), curl_getinfo($ch, CURLINFO_HTTP_CODE));
                curl_close($ch);

                throw  $e;
            }

            curl_close($ch);

            return $this->decode($response);
        } catch (XmlrpcException $e) {
            throw new TransportException('XML parsing error', 0, $e);
        }
    }