コード例 #1
0
ファイル: WebTestCase.php プロジェクト: brennantom/hackazon
 /**
  * @return null|Request
  */
 protected function getRequest()
 {
     if (!$this->client) {
         return null;
     }
     return $this->client->getRequest();
 }
コード例 #2
0
 /**
  * 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
0
ファイル: IndexerTest.php プロジェクト: gpupo/camelspider
 /**
  * @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
0
ファイル: Document.php プロジェクト: aakb/bpi-client
 /**
  * Dump latest raw request data
  *
  * @return string
  */
 public function dumpRawRequest()
 {
     return print_r($this->http_client->getRequest(), true);
 }
コード例 #5
0
ファイル: Charlotte.php プロジェクト: randak/charlotte
 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 " . $url . " in " . number_format($end - $start, 2, ".", "") . " seconds" . " with response code 200" . PHP_EOL;
             } else {
                 echo "Page not indexed at " . $url . " due to status " . $statusCode . "" . 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
0
ファイル: a05.php プロジェクト: ixtel/tsugi
 $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
0
 /**
  * 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();
 }