本文整理汇总了PHP中Goutte\Client::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getRequest方法的具体用法?PHP Client::getRequest怎么用?PHP Client::getRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Goutte\Client
的用法示例。
在下文中一共展示了Client::getRequest方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequest
/**
* @return null|Request
*/
protected function getRequest()
{
if (!$this->client) {
return null;
}
return $this->client->getRequest();
}
示例2: loginToOrange
/**
* Call orange portal and submit credentials
* @return [type] [description]
*/
protected function loginToOrange()
{
$config = $this->getHelperSet()->get('config');
$this->outputMessage('Login to orange wifi ...');
// Forge form submit as there is no button or input
$parameters = array('username' => $config['login'], 'password' => $config['pass'], 'isCgu' => 'true', 'code' => 0, 'lang' => 'fr', 'auth' => 1, 'restrictedCode' => '', 'restrictedProfile' => 0, 'restrictedRealm' => '', 'originForm' => 'true', 'tab' => '1');
try {
$client = new Client();
$crawler = $client->request('POST', 'https://hautdebitmobile.orange.fr:8443/home/wassup', $parameters);
} catch (\Exception $e) {
$this->outputError('Connection error : ' . $e->getMessage(), true);
exit(1);
}
// If login is a success, we should have follow the redirect to orange home page
if ($client->getRequest()->getUri() == 'http://www.orange.fr') {
$this->outputMessage('Login success !');
} else {
$error_mssg = 'Login failed';
$div_error = $crawler->filterXPath("//div[@id='loginFormWassupErrorMessage']");
if ($div_error->count() == 1) {
$error_mssg .= ' : ' . trim($div_error->text());
}
$this->outputError($error_mssg);
// Output raw reponse if (-vv)
if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) {
echo $client->getResponse();
}
return 1;
}
}
示例3: testNavigation
/**
* @dataProvider providerNavigation()
*/
public function testNavigation($host, $paths)
{
$client = new Client();
//Test with absolute path
foreach ($paths as $path) {
$uri = 'http://' . $host . $path;
$crawler = $client->request('GET', $uri);
$this->assertEquals(200, $client->getResponse()->getStatus());
$this->assertEquals($uri, $client->getRequest()->getUri());
}
//Test with relative path and get absolute URI
foreach ($paths as $path) {
$uri = 'http://' . $host . $path;
$crawler = $client->request('GET', $path);
$this->assertEquals(200, $client->getResponse()->getStatus());
$this->assertEquals($uri, $client->getRequest()->getUri());
}
}
示例4: dumpRawRequest
/**
* Dump latest raw request data
*
* @return string
*/
public function dumpRawRequest()
{
return print_r($this->http_client->getRequest(), true);
}
示例5: processPage
protected function processPage($url)
{
try {
$start = microtime(true);
$client = new Client();
$crawler = $client->request("GET", $url);
$url = $this->regulateURL($client->getRequest()->getUri());
//don't crawl HTTPS version of HTTP page
$alt = '';
$prot = $this->getProtocol($url);
if ($prot === "https://") {
$alt = preg_replace("/https:\\/\\//", "http://", $url);
}
if (!in_array($url, $this->traversed) && !in_array($alt, $this->traversed)) {
array_push($this->traversed, $url);
$statusCode = $client->getResponse()->getStatus();
if ($statusCode == 200) {
//VALID URL
$page = array();
$page["url"] = $url;
$page["title"] = $this->getTitle($crawler, $url);
$page["metas"] = $this->getMetaTags($crawler, $url);
$page["h1s"] = $this->getH1s($crawler, $url);
$page["scripts"] = $this->getScripts($crawler, $url);
$page["stylesheets"] = $this->getStylesheets($crawler, $url);
// $page["keywords"] = $this->getKeywords($crawler, $url);
$page["links"] = $this->getLinks($crawler, $url);
$this->processor->process($page);
$end = microtime(true);
echo "Page indexed at [33m" . $url . "[0m in [36m" . number_format($end - $start, 2, ".", "") . " seconds[0m" . " with response code [32m200[0m" . PHP_EOL;
} else {
echo "Page not indexed at [31m" . $url . "[0m due to status [31m" . $statusCode . "[0m" . PHP_EOL;
}
} else {
// echo "Page ignored (already indexed) at \033[31m".$url."\033[0m".PHP_EOL;
}
} catch (\Guzzle\Http\Exception\CurlException $ex) {
} catch (\Exception $ex) {
}
}
示例6:
$crawler = $client->request('GET', $url);
$html = $crawler->html();
$OUTPUT->togglePre("Show retrieved page", $html);
$passed++;
// Log in fail
line_out("Looking for the form with a 'Log In' submit button");
$form = $crawler->selectButton('Log In')->form();
// var_dump($form->getPhpValues());
line_out("Setting bad account and pw fields in the form");
$form->setValues(array("account" => "bob", "pw" => "hellokitty"));
$crawler = $client->submit($form);
$passed++;
$html = $crawler->html();
$OUTPUT->togglePre("Show retrieved page", $html);
line_out("Checking to see if there was a POST redirect to a GET");
$method = $client->getRequest()->getMethod();
if ($method == "get") {
$passed++;
} else {
error_out('Expecting POST to Redirect to GET - found ' . $method);
}
line_out("Looking for a red 'Incorrect password' message");
if (stripos($html, 'Incorrect password') !== false) {
$passed++;
} else {
error_out("Could not find 'Incorrect password'");
}
// Log in correctly
line_out("Setting the correct account and pw fields in the form");
$form->setValues(array("account" => "bob", "pw" => "umsi"));
$crawler = $client->submit($form);
示例7: get_uri_from_client
/**
* Get the requested uri from a Client object.
*
* @param Client $client
* @return string
*/
protected static function get_uri_from_client(Client $client)
{
return $client->getRequest()->getUri();
}