本文整理汇总了PHP中Guzzle\Http\Client::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::get方法的具体用法?PHP Client::get怎么用?PHP Client::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scrape
/**
* Scrape URL and collect output
* @param string $url
* @param OutputInterface $output
*/
public function scrape($url, OutputInterface $output)
{
$this->collection->exchangeArray([]);
try {
$initialPage = $this->client->get($url)->send();
} catch (BadResponseException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
throw new \RuntimeException('Unable to load initial page');
}
$xml = $this->getSimpleXml($initialPage->getBody());
$items = $xml->xpath($this->config['collection']);
foreach ($items as $item) {
$title = $item->xpath($this->config['title']);
$unitPrice = $item->xpath($this->config['unitPrice']);
$itemUrl = $item->xpath($this->config['itemUrl']);
$itemSize = 0;
$itemDesc = null;
if (isset($itemUrl[0]->attributes()['href'])) {
try {
$itemPage = $this->client->get((string) $itemUrl[0]->attributes()['href'])->send();
$itemPageBody = $this->getSimpleXml($itemPage->getBody());
$itemSize = $itemPage->getContentLength();
$itemDesc = $itemPageBody->xpath($this->config['desc']);
} catch (BadResponseException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
}
}
if ($title && $unitPrice) {
$parsedPrice = (double) \trim(\str_replace('£', null, $unitPrice[0]));
$this->collection->append(['title' => \trim($title[0]), 'unit_price' => $parsedPrice, 'description' => \trim($itemDesc[0]), 'size' => \round($itemSize / 1024) . 'kb']);
}
}
return $this->collection;
}
示例2: lookupAddress
/**
* @param string $postalCode
* @param string $houseNumber
* @return array
*/
public function lookupAddress($postalCode, $houseNumber)
{
$this->client->setConfig(['curl.options' => ['CURLOPT_CONNECTTIMEOUT_MS' => '2000', 'CURLOPT_RETURNTRANSFER' => true]]);
$url = sprintf($this->baseUrl . '/%s/%s', $postalCode, $houseNumber);
$request = $this->client->get($url)->setAuth($this->apiKey, $this->apiSecret);
return $request->send()->json();
}
示例3: getDocument
/**
* @return \DOMDocument
*/
public function getDocument()
{
$request = $this->client->get($this->url);
$this->response = $request->send();
$this->setHtml($this->response->getBody(true));
return parent::getDocument();
}
示例4: injectScript
/**
* Injects the livereload script.
*
* @param Response $response A Response instance
*/
protected function injectScript(Response $response)
{
if (function_exists('mb_stripos')) {
$posrFunction = 'mb_strripos';
$substrFunction = 'mb_substr';
} else {
$posrFunction = 'strripos';
$substrFunction = 'substr';
}
$content = $response->getContent();
$pos = $posrFunction($content, '</body>');
if (false !== $pos) {
$script = "livereload.js";
if ($this->checkServerPresence) {
// GET is required, as livereload apparently does not support HEAD requests ...
$request = $this->httpClient->get($script);
try {
$checkResponse = $this->httpClient->send($request);
if ($checkResponse->getStatusCode() !== 200) {
return;
}
} catch (CurlException $e) {
// If error is connection failed, we assume the server is not running
if ($e->getCurlHandle()->getErrorNo() === 7) {
return;
}
throw $e;
}
}
$content = $substrFunction($content, 0, $pos) . "\n" . '<script src="' . $this->httpClient->getBaseUrl() . $script . '"></script>' . "\n" . $substrFunction($content, $pos);
$response->setContent($content);
}
}
示例5: get
/**
* @inheritdoc
*/
public function get($url)
{
$request = $this->client->get($url);
$this->setHeaders($request);
$response = $request->send();
return json_decode($response->getBody(true));
}
示例6: parse
/**
* parse
*
* @param string $text
*
* @return array
*/
public function parse($text)
{
$request = $this->client->get();
$request->getQuery()->set('text', $text);
$data = $request->send()->json();
return $this->processSuggestions($text, $data);
}
示例7: authenticate
public function authenticate(array $credentials)
{
$mcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($mcrypt), MCRYPT_DEV_RANDOM);
mcrypt_generic_init($mcrypt, $this->cryptPassword, $iv);
$url = $this->getUrl($credentials[self::USERNAME], $credentials[self::PASSWORD], $mcrypt, $iv);
try {
$res = $this->httpClient->get($url)->send();
} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {
if ($e->getResponse()->getStatusCode() === 403) {
throw new \Nette\Security\AuthenticationException("User '{$credentials[self::USERNAME]}' not found.", self::INVALID_CREDENTIAL);
} elseif ($e->getResponse()->getStatusCode() === 404) {
throw new \Nette\Security\AuthenticationException("Invalid password.", self::IDENTITY_NOT_FOUND);
} else {
throw $e;
}
}
$responseBody = trim(mdecrypt_generic($mcrypt, $res->getBody(TRUE)));
$apiData = Json::decode($responseBody);
$user = $this->db->table('users')->where('id = ?', $apiData->id)->fetch();
$registered = new \DateTimeImmutable($apiData->registered->date, new \DateTimeZone($apiData->registered->timezone));
$userData = array('username' => $credentials[self::USERNAME], 'password' => $this->calculateAddonsPortalPasswordHash($credentials[self::PASSWORD]), 'email' => $apiData->email, 'realname' => $apiData->realname, 'url' => $apiData->url, 'signature' => $apiData->signature, 'language' => $apiData->language, 'num_posts' => $apiData->num_posts, 'apiToken' => $apiData->apiToken, 'registered' => $registered->getTimestamp());
if (!$user) {
$userData['id'] = $apiData->id;
$userData['group_id'] = 4;
$this->db->table('users')->insert($userData);
$user = $this->db->table('users')->where('username = ?', $credentials[self::USERNAME])->fetch();
} else {
$user->update($userData);
}
return $this->createIdentity($user);
}
示例8: product
/**
* Query product
*
* @param $productId
* @return mixed
*/
public function product($productId)
{
$query = ['apikey' => Config::get('providers.' . $this->provider)['apikey']];
$url = $this->baseUrl . "products/{$productId}?" . http_build_query($query);
$request = $this->client->get($url);
$response = $request->send();
return $response->json()['products'][0];
}
示例9: get
/**
* @param string $uri
* @param array $params
* @param null $headers
* @return array|null
*/
public function get($uri, $params = [], $headers = null)
{
if (!empty($params)) {
$uri .= '?' . http_build_query($params);
}
$response = $this->client->get($uri, $headers)->send();
return $this->parseResponse($response);
}
示例10: getFileContent
/**
* @param string $file
* @return string
*/
public function getFileContent($file)
{
$request = $this->client->get('/exports/openstackcert/' . $file);
$request->setAuth(COA_FILE_API_BASE_USER, COA_FILE_API_BASE_PASS);
$response = $request->send();
$content = (string) $response->getBody();
return $content;
}
示例11: getLinhas
public function getLinhas($termosBusca)
{
$request = $this->client->get('Linha/Buscar');
$request->addCookie('apiCredentials', $this->apiCredentials);
$request->getQuery()->set('termosBusca', $termosBusca);
$response = $request->send();
return $response->json();
}
示例12: getUserDetails
/**
* Return the current users information
*
* @param Array $authorization
* @return Array
*/
public function getUserDetails(array $authorization)
{
$endpoint = "people/me.json";
$url = "{$authorization['accounts'][0]['href']}/{$endpoint}";
$whoami = $this->client->get($url)->send()->json();
$avatar = parse_url($whoami['avatar_url']);
return ['name' => $whoami['name'], 'firstName' => $authorization['identity']['first_name'], 'lastName' => $authorization['identity']['last_name'], 'email' => $whoami['email_address'], 'avatar' => "//{$avatar['host']}/{$avatar['path']}?{$avatar['query']}"];
}
示例13: prepareRequest
/**
* @param string $method
* @param array $context
* @return \Guzzle\Http\Message\RequestInterface
*/
protected function prepareRequest($method, $context = array())
{
$request = $this->client->get($method);
$query = $request->getQuery();
foreach ($context as $key => $value) {
$query->set($key, $value);
}
return $request;
}
示例14: get
/**
* @param string $uri
* @param array $headers
* @param array $options
* @return array|\Guzzle\Http\Message\Response|null
*/
public function get($uri, $headers = [], $options = [])
{
if (!$uri) {
return null;
}
$this->request = $this->client->get($uri, $headers, $options);
$this->response = $this->request->send();
return $this->response;
}
示例15: handle
/**
* {@inheritdoc}
*/
public function handle($workload)
{
/** @var PageDocument $document */
$document = $this->documentManager->find($workload['uuid'], $workload['locale']);
$urls = $this->webspaceManager->findUrlsByResourceLocator($document->getResourceSegment(), $this->environment, $workload['locale'], $workload['webspaceKey']);
foreach ($urls as $url) {
$this->client->get($url)->send();
}
}