public function Client::createRequest

Create and return a new { Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URI can contain the query string as well. Use an array to provide a URI template and additional variables to use in the URI template expansion.

Parameters

string $method HTTP method. Defaults to GET:

string|array $uri Resource URI.:

array|Collection $headers HTTP headers:

string|resource|array|EntityBodyInterface $body Entity body of request (POST/PUT) or response (GET):

Return value

RequestInterface

Throws

InvalidArgumentException if a URI array is passed that does not contain exactly two elements: the URI followed by template variables

Overrides ClientInterface::createRequest

See also

RequestInterface} configured for the client.

7 calls to Client::createRequest()
Client::delete in drupal/core/vendor/guzzle/http/Guzzle/Http/Client.php
Create a DELETE request for the client
Client::get in drupal/core/vendor/guzzle/http/Guzzle/Http/Client.php
Create a GET request for the client
Client::head in drupal/core/vendor/guzzle/http/Guzzle/Http/Client.php
Create a HEAD request for the client
Client::options in drupal/core/vendor/guzzle/http/Guzzle/Http/Client.php
Create an OPTIONS request for the client
Client::patch in drupal/core/vendor/guzzle/http/Guzzle/Http/Client.php
Create a PATCH request for the client

... See full list

File

drupal/core/vendor/guzzle/http/Guzzle/Http/Client.php, line 225

Class

Client
HTTP client

Namespace

Guzzle\Http

Code

public function createRequest($method = RequestInterface::GET, $uri = null, $headers = null, $body = null) {
  if (!is_array($uri)) {
    $templateVars = null;
  }
  else {
    if (count($uri) != 2 || !isset($uri[1]) || !is_array($uri[1])) {
      throw new InvalidArgumentException('You must provide a URI template followed by an array of template variables ' . 'when using an array for a URI template');
    }
    list($uri, $templateVars) = $uri;
  }
  if (!$uri) {
    $url = $this
      ->getBaseUrl();
  }
  elseif (substr($uri, 0, 4) === 'http') {

    // Use absolute URLs as-is
    $url = $this
      ->expandTemplate($uri, $templateVars);
  }
  else {
    $url = Url::factory($this
      ->getBaseUrl())
      ->combine($this
      ->expandTemplate($uri, $templateVars));
  }
  if ($this->userAgent) {
    $this->defaultHeaders
      ->set('User-Agent', $this->userAgent);
  }

  // If default headers are provided, then merge them into existing headers
  // If a collision occurs, the header is completely replaced
  if (count($this->defaultHeaders)) {
    if ($headers instanceof Collection) {
      $headers = array_merge($this->defaultHeaders
        ->getAll(), $headers
        ->getAll());
    }
    elseif (is_array($headers)) {
      $headers = array_merge($this->defaultHeaders
        ->getAll(), $headers);
    }
    else {
      $headers = $this->defaultHeaders;
    }
  }
  return $this
    ->prepareRequest($this->requestFactory
    ->create($method, (string) $url, $headers, $body));
}