Symfony\Component\BrowserKit\Client::request PHP Method

request() public method

Calls a URI.
public request ( string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, boolean $changeHistory = true ) : Crawler
$method string The request method
$uri string The URI to fetch
$parameters array The Request parameters
$files array The files
$server array The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)
$content string The raw body data
$changeHistory boolean Whether to update the history or not (only used internally for back(), forward(), and reload())
return Symfony\Component\DomCrawler\Crawler
    public function request($method, $uri, array $parameters = array(), array $files = array(), array $server = array(), $content = null, $changeHistory = true)
    {
        $uri = $this->getAbsoluteUri($uri);

        $server = array_merge($this->server, $server);
        if (!$this->history->isEmpty()) {
            $server['HTTP_REFERER'] = $this->history->current()->getUri();
        }
        $server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
        $server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);

        $request = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);

        $this->request = $this->filterRequest($request);

        if (true === $changeHistory) {
            $this->history->add($request);
        }

        if ($this->insulated) {
            $this->response = $this->doRequestInProcess($this->request);
        } else {
            $this->response = $this->doRequest($this->request);
        }

        $response = $this->filterResponse($this->response);

        $this->cookieJar->updateFromResponse($response);

        $this->redirect = $response->getHeader('Location');

        if ($this->followRedirects && $this->redirect) {
            return $this->crawler = $this->followRedirect();
        }

        return $this->crawler = $this->createCrawlerFromContent($request->getUri(), $response->getContent(), $response->getHeader('Content-Type'));
    }

Usage Example

Example #1
0
 /**
  * @return AuthenticateResponse
  */
 public function authenticate()
 {
     $this->client->request('POST', self::SING_IN_URI, ['username' => $this->username, 'password' => $this->password], [], ['HTTP_ACCEPT' => 'application/json']);
     $loginResponse = json_decode($this->client->getResponse()->getContent());
     $authenticateHeaders = ['HTTP_TOKEN' => isset($loginResponse->Token) ? $loginResponse->Token : null, 'HTTP_EXPIREAT' => isset($loginResponse->ExpireAt) ? $loginResponse->ExpireAt : null, 'HTTP_USERNAME' => isset($loginResponse->Username) ? $loginResponse->Username : null];
     return new AuthenticateResponse([], $authenticateHeaders);
 }
All Usage Examples Of Symfony\Component\BrowserKit\Client::request