當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。