当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::getResponse方法代码示例

本文整理汇总了PHP中Goutte\Client::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getResponse方法的具体用法?PHP Client::getResponse怎么用?PHP Client::getResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Goutte\Client的用法示例。


在下文中一共展示了Client::getResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addProduct

 /**
  * Add product data
  *
  * @param Crawler $node
  */
 private function addProduct(Crawler $node)
 {
     $product = new \stdClass();
     /** @var Crawler $title */
     $title = $node->filter('h3 a');
     $product->title = trim($title->text());
     $product->unit_price = $this->getPrice($node->filter('.pricePerUnit'));
     $productCrawler = $this->client->request('GET', $title->attr('href'));
     $product->size = $this->bytesToKb(strlen($this->client->getResponse()->getContent()));
     $product->description = '';
     $description = $productCrawler->filterXPath('//h3[.="Description"]');
     if ($description->count() > 0) {
         foreach ($description->siblings() as $sibling) {
             // product pages have different structures!
             if ($sibling->tagName == 'h3') {
                 break;
             }
             if ($product->description != "") {
                 $product->description .= "\n";
             }
             // @TODO address formatting issues - breaks to new lines
             $product->description .= trim(preg_replace("/[^\\S\r\n]+/", " ", $sibling->nodeValue));
             // remove excess whitespace but not new lines
         }
     }
     $this->total += $product->unit_price;
     // increment total
     $this->results[] = $product;
 }
开发者ID:peterhough,项目名称:sainsburys,代码行数:34,代码来源:Scraper.php

示例2: testUserSeesPageTitle

 public function testUserSeesPageTitle()
 {
     $client = new Client();
     $crawler = $client->request('GET', 'http://localhost:8000/lists');
     $this->assertEquals(200, $client->getResponse()->getStatus());
     $this->assertCount(1, $crawler->filter('h1:contains("Lists")'));
 }
开发者ID:shk33,项目名称:todo-parrot,代码行数:7,代码来源:ListsTest.php

示例3: testLoggedIn

 public function testLoggedIn()
 {
     // we don't use the trait method here since we want our
     // test to span two page requests, and we need to have
     // the session persist on the remote server
     // create a web client and hit the login page
     $url = "http://localhost/login";
     $client = new Client();
     $crawler = $client->request('GET', $url);
     $response_code = $client->getResponse()->getStatus();
     // we should get 200 back
     $this->assertEquals(200, $response_code);
     // select the form on the page and populate values
     // since we are using Goutte\Client, we don't need
     // to worry about parsing the HTML to find the csrf _token
     $form = $crawler->selectButton('Sign in')->form();
     $form->setValues(['email' => 'me@here.ca', 'password' => 'verysecret']);
     // submit the form
     $client->submit($form);
     $response_code_after_submit = $client->getResponse()->getStatus();
     // make sure the HTML page displayed (response code 200
     $this->assertEquals(200, $response_code_after_submit);
     // make sure we can get to the testimonial page
     $client->request('GET', 'http://localhost/add-testimonial');
     $response_code = $client->getResponse()->getStatus();
     $this->assertEquals(200, $response_code);
 }
开发者ID:tcs-udemy,项目名称:introduction-to-unit-testing,代码行数:27,代码来源:LoggedInTest.php

示例4: testSyncVendingMachineLoads

 public function testSyncVendingMachineLoads()
 {
     $vendingMachineConnectionPath = sprintf("%s?%s", $this->getVendingMachineSerial(), $this->getVendingMachineAuthentificationString());
     $vendingMachineConnectionUrl = $this->getVendingMachineConnectionUrl($vendingMachineConnectionPath);
     $client = new Client();
     $client->request(VendingMachineLoad::getSyncMethod(), $vendingMachineConnectionUrl, [], [], ['CONTENT_TYPE' => 'application/json'], VendingMachineLoad::getData());
     $this->assertEquals(200, $client->getResponse()->getStatus());
     $this->assertEquals('null', $client->getResponse()->getContent());
 }
开发者ID:Kid-Binary,项目名称:Boilerplate,代码行数:9,代码来源:SyncControllerTest.php

示例5: getResponse

 /**
  * @return null|Response
  */
 protected function getResponse()
 {
     if (!$this->client) {
         return null;
     }
     return $this->client->getResponse();
 }
开发者ID:brennantom,项目名称:hackazon,代码行数:10,代码来源:WebTestCase.php

示例6: fetchDetails

 private function fetchDetails()
 {
     $url = 'https://www.twitter.com/' . $this->getAccountName();
     $client = new Client();
     $client->followRedirects();
     $crawler = $client->request('GET', $url);
     /**
      * @var Response $response
      */
     $response = $client->getResponse();
     if ($response->getStatus() != '200') {
         $this->setIsNotFound(true);
         return false;
     }
     // --
     if (stripos($response->getContent(), 'suspended')) {
         $this->setIsSuspended(true);
         return false;
     }
     // --
     $post_times = $crawler->filter('#stream-items-id li ._timestamp')->each(function (Crawler $node) {
         return $node->attr('data-time');
     });
     rsort($post_times);
     $last_post_time = $post_times[0];
     $hour_difference = round((time() - $last_post_time) / 60 / 60, 2);
     if ($hour_difference > 24) {
         // if last post was later than 24 hours
         $this->setDoesntHaveRecentPosts(true);
     }
 }
开发者ID:Gyvastis,项目名称:twitter-account-checker,代码行数:31,代码来源:AccountFilter.php

示例7: run

 /**
  * @param boolean $allPages
  */
 public function run($allPages)
 {
     $client = new Client();
     $client->getClient()->setDefaultOption('config/curl/' . CURLOPT_TIMEOUT, 30);
     $client->setHeader('User-Agent', $this->config['user_agent']);
     try {
         $crawler = $client->request('GET', $this->config['url']);
     } catch (TransferException $e) {
         echo $e->getMessage() . PHP_EOL;
         exit(1);
     }
     if ($client->getResponse()->getStatus() == 200) {
         $this->getUrlsAndDownload($crawler);
         if ($allPages) {
             $link = $this->getNextLink($crawler);
             while ($link) {
                 $crawler = $client->click($link);
                 $this->getUrlsAndDownload($crawler);
                 $link = $this->getNextLink($crawler);
             }
         }
     } else {
         echo "site not available\n";
     }
 }
开发者ID:athlonUA,项目名称:xakep-crawler,代码行数:28,代码来源:Crawler.php

示例8: 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;
     }
 }
开发者ID:zeliard91,项目名称:orange-hotspot,代码行数:34,代码来源:CheckCommand.php

示例9: crawl

 /**
  * return response code when crawling a given url
  * @param $url
  * @return mixed
  */
 function crawl($url)
 {
     $client = new Client();
     $client->request('GET', $url);
     $response_code = $client->getResponse()->getStatus();
     return $response_code;
 }
开发者ID:tcs-udemy,项目名称:introduction-to-unit-testing,代码行数:12,代码来源:CrawlTrait.php

示例10: TestUserSeesWelcomeMessage

 public function TestUserSeesWelcomeMessage()
 {
     $client = new Client();
     $crawler = $client->request('GET', 'http://homestead.app/');
     $this->assertEquals(200, $client->getResponse()->getStatus());
     $this->assertCount(1, $crawler->filter('h1:contains("Welcome to TODOParrot")'));
 }
开发者ID:ahmadi1994,项目名称:todoparrot,代码行数:7,代码来源:WelcomeTest.php

示例11: traverseSingle

 /**
  * Crawl single URL
  * @param string $url
  * @param int    $depth
  */
 protected function traverseSingle($url, $depth)
 {
     try {
         $client = new Client();
         $client->followRedirects();
         $crawler = $client->request('GET', $url);
         $statusCode = $client->getResponse()->getStatus();
         $hash = $this->getPathFromUrl($url);
         $this->links[$hash]['status_code'] = $statusCode;
         if ($statusCode === 200) {
             $content_type = $client->getResponse()->getHeader('Content-Type');
             if (strpos($content_type, 'text/html') !== false) {
                 //traverse children in case the response in HTML document only
                 $this->extractTitleInfo($crawler, $hash);
                 $childLinks = array();
                 if (isset($this->links[$hash]['external_link']) === true && $this->links[$hash]['external_link'] === false) {
                     $childLinks = $this->extractLinksInfo($crawler, $hash);
                 }
                 $this->links[$hash]['visited'] = true;
                 $this->traverseChildren($childLinks, $depth - 1);
             }
         }
     } catch (CurlException $e) {
         $this->links[$url]['status_code'] = '404';
         $this->links[$url]['error_code'] = $e->getCode();
         $this->links[$url]['error_message'] = $e->getMessage();
     } catch (\Exception $e) {
         $this->links[$url]['status_code'] = '404';
         $this->links[$url]['error_code'] = $e->getCode();
         $this->links[$url]['error_message'] = $e->getMessage();
     }
 }
开发者ID:nunodotferreira,项目名称:arachnid,代码行数:37,代码来源:Crawler.php

示例12: postOauth2Token

 /**
  * @param $basic
  * @return mixed
  * @throws \Exception
  */
 public function postOauth2Token($basic)
 {
     $rquestBody = 'grant_type=client_credentials';
     $this->client->setHeader('Authorization', 'Basic ' . $basic);
     $this->client->setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
     $this->client->request('POST', $this->getApiBaseUrl() . '/' . $this->authenticationUri, [], [], [], $rquestBody);
     /**
      * @var $response Response
      */
     $response = $this->client->getResponse();
     $decodedResponse = json_decode($response->getContent(), true);
     $lastError = json_last_error();
     if ($lastError !== JSON_ERROR_NONE) {
         throw new \Exception('An error occurred when decoding the response (Error code: ' . $lastError . ')');
     }
     return $decodedResponse;
 }
开发者ID:WeavingTheWeb,项目名称:devobs,代码行数:22,代码来源:ApplicationAuthenticator.php

示例13: detect

 /**
  * Funcion con la que realizaremos la deteccion de tipo de foro que nos estan solicitando
  * @param type $name
  * @return type
  */
 public function detect()
 {
     $client = new Client();
     $crawler = $client->request($this->method, $this->uri);
     $client->getResponse()->getStatus();
     // Filtramos por metas
     $crawler->filter($metas)->each(function (Crawler $node, $i) {
     });
 }
开发者ID:adavom,项目名称:webCrawler,代码行数:14,代码来源:DefaultController.php

示例14: request

 public function request($url, $method = 'GET', $parameters = array())
 {
     if (strpos($url, '/') === 0) {
         $url = 'http://' . $_SERVER['SERVER_NAME'] . $url;
     }
     $client = new Client();
     $client->request($method, $url, $parameters);
     return $client->getResponse()->getContent();
 }
开发者ID:nexik,项目名称:http_client,代码行数:9,代码来源:HttpClient.php

示例15: testSubmitFormOk

 public function testSubmitFormOk()
 {
     $client = new Client();
     $crawler = $client->request('GET', 'http://localhost');
     $form = $crawler->selectButton('OK')->form();
     $crawler = $client->submit($form);
     $this->assertEquals(200, $client->getResponse()->getStatus());
     $this->assertEquals('Data successfully submitted', $crawler->filter('.message')->text());
 }
开发者ID:NicParry,项目名称:SimpleFormExample,代码行数:9,代码来源:IntegrationTest.php


注:本文中的Goutte\Client::getResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。