Imdb\Pages::requestPage PHP Méthode

requestPage() protected méthode

Request the page from IMDb
protected requestPage ( $url ) : string
$url
Résultat string Page html. Empty string on failure
    protected function requestPage($url)
    {
        $this->logger->info("[Page] Requesting [{$url}]");
        $req = $this->buildRequest($url);
        if (!$req->sendRequest()) {
            $this->logger->error("[Page] Failed to connect to server when requesting url [{$url}]");
            if ($this->config->throwHttpExceptions) {
                throw new Exception\Http("Failed to connect to server when requesting url [{$url}]");
            } else {
                return '';
            }
        }
        if (200 == $req->getStatus()) {
            return $req->getResponseBody();
        } elseif ($redirectUrl = $req->getRedirect()) {
            $this->logger->debug("[Page] Following redirect from [{$url}] to [{$redirectUrl}]");
            return $this->requestPage($redirectUrl);
        } else {
            $this->logger->error("[Page] Failed to retrieve url [{url}]. Response headers:{headers}", array('url' => $url, 'headers' => $req->getLastResponseHeaders()));
            if ($this->config->throwHttpExceptions) {
                $exception = new Exception\Http("Failed to retrieve url [{$url}]. Status code [{$req->getStatus()}]");
                $exception->HTTPStatusCode = $req->getStatus();
                throw new $exception();
            } else {
                return '';
            }
        }
    }