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


PHP Client::send方法代码示例

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


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

示例1: 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);
     }
 }
开发者ID:bakie,项目名称:KunstmaanBundlesCMS,代码行数:38,代码来源:ScriptInjectorListener.php

示例2: getStatusFromWoeid

 public function getStatusFromWoeid($woeid)
 {
     $request = $this->guzzle->createRequest(self::WEBSERVICE_METHOD, self::WEBSERVICE_URI . $woeid);
     $response = $this->guzzle->send($request);
     $status = $this->parseWeatherResponse($response->xml());
     return $status;
 }
开发者ID:salvador-lopez,项目名称:weather,代码行数:7,代码来源:Weather.php

示例3: send

 /**
  * Returns a response for specified HTTP request.
  *
  * @param Request $request HTTP Request to send.
  *
  * @return Response Response for specified request.
  */
 public function send(Request $request)
 {
     try {
         $response = $this->client->send($request);
     } catch (BadResponseException $e) {
         $response = $e->getResponse();
     }
     return new Response($response->getStatusCode(), $response->getHeaders(), $response->getBody());
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:16,代码来源:HttpClient.php

示例4: iSendAGetRequestTo

 /**
  * @When I send a GET request to :path
  */
 public function iSendAGetRequestTo($path)
 {
     $request = $this->guzzleClient->get('http://localhost:8081' . $path);
     try {
         $this->lastResponse = $this->guzzleClient->send($request);
     } catch (GuzzleResponseException $guzzleResponseException) {
         $this->lastResponse = $guzzleResponseException->getResponse();
     }
 }
开发者ID:cbindika,项目名称:rest-in-peace,代码行数:12,代码来源:WebserverContext.php

示例5: getContentEntryBy

 /**
  * @param $spaceId
  * @param array $attributes
  * @return array|\Guzzle\Http\Message\Response|null
  */
 public function getContentEntryBy($spaceId, $contentType, $attributes = [])
 {
     $path = sprintf(self::CONTENTFUL_ENTRIES_URL . "&content_type=%s", $spaceId, $this->accessToken, $contentType);
     foreach ($attributes as $attr => $value) {
         $path .= sprintf("&%s=%s", $attr, $value);
     }
     $request = $this->guzzleClient->get($path, [self::CONTENTFUL_HEADERS_V1_JSON]);
     $response = $this->guzzleClient->send($request);
     return $response;
 }
开发者ID:rudirocha,项目名称:contentfulBundle,代码行数:15,代码来源:ContentDeliveryService.php

示例6: processQuery

 /**
  * @param string $url
  * @param array  $headers
  * @param array  $options
  *
  * @return array|null
  * @throws \Exception
  */
 public function processQuery($url, $headers = array(), $options = array())
 {
     $request = $this->client->get($url, $headers, $options);
     /**@var Response */
     $response = $this->client->send($request);
     if ($response->isSuccessful()) {
         try {
             return $response->json();
         } catch (RuntimeException $cannotParseJsonException) {
             return $response->getBody(true);
         }
     } else {
         throw new \Exception("Fail to complete the request. Server returns code {$response->getStatusCode()}");
     }
 }
开发者ID:haphan,项目名称:php-rage4dns,代码行数:23,代码来源:AbstractRage4DNS.php

示例7: getResponse

 /**
  * Get RealFaviconGenerator response
  *
  * @param QueryData $queryData RealFaviconGenerator query
  * @return mixed RealFaviconGenerator response
  */
 protected function getResponse(QueryData $queryData)
 {
     $client = new Client($this->generator->getBaseurl());
     $request = $client->post($this->generator->getUri(), null, $queryData->__toString());
     $response = $client->send($request);
     return $response;
 }
开发者ID:noodle69,项目名称:EdgarEzFaviconBundle,代码行数:13,代码来源:FaviconCommand.php

示例8: makeHttpRequest

 /**
  * Use guzzle to make request to API
  *
  * @param Request $request
  * @return string
  */
 protected function makeHttpRequest($request)
 {
     $url = $this->urlBuilder->build($request);
     $guzzleRequest = $this->guzzle->createRequest('GET', $url);
     $guzzleResponse = $this->guzzle->send($guzzleRequest);
     return $guzzleResponse->getBody();
 }
开发者ID:sojimaxi,项目名称:semrush-api,代码行数:13,代码来源:Client.php

示例9: __construct

 public function __construct($token)
 {
     $client = new Client();
     $request = new Request('POST', self::API_BASE_URL . 'rtm.start?' . http_build_query(['token' => $token]), ['Content-Type' => 'application/x-www-form-urlencoded']);
     $response = $client->send($request);
     var_dump(json_decode($response->getBody(true)));
 }
开发者ID:kix,项目名称:lykov,代码行数:7,代码来源:ApiClient.php

示例10: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->hasOption('input-file') && $input->getOption('input-file')) {
         $commentFilePath = $input->getOption('input-file');
         if (!file_exists($commentFilePath)) {
             throw new \Exception("{$commentFilePath} not found");
         }
         $commentText = file_get_contents($commentFilePath);
     } else {
         if ($input->hasOption('string') && $input->getOption('string')) {
             $commentText = $input->getOption('string');
         }
     }
     if (!$commentText) {
         throw new \Exception('No comment input, add a comment text with -s or -i options');
     }
     $client = new Client();
     $request = $client->createRequest('GET', 'https://www.pivotaltracker.com/services/v5/me', array('X-TrackerToken' => 'be17fcf368af9fa35cfe88b7460d2c67'));
     $response = $client->send($request);
     $this->projects = array_map(function ($item) {
         return $item['project_id'];
     }, json_decode($response->getBody(), true)['projects']);
     $labelsList = implode(',', $this->projects);
     $extractor = new StoriesExtractor();
     $storyIds = $extractor->collect();
     $storyCount = count($storyIds);
     $output->writeln("Adding comments on {$storyCount} stories on projects {$labelsList}");
     foreach ($storyIds as $storyId) {
         foreach ($this->projects as $project) {
             $request = $client->createRequest('POST', "https://www.pivotaltracker.com/services/v5/projects/{$project}/stories/{$storyId}/comments");
             $request->setHeader('X-TrackerToken', 'be17fcf368af9fa35cfe88b7460d2c67');
             $request->setHeader('Content-type', 'application/json');
             $request->setHeader('Accept', 'application/json');
             $request->setBody(json_encode(['text' => $commentText]));
             try {
                 $client->send($request);
                 $output->write('.');
                 break;
             } catch (ClientErrorResponseException $ex) {
                 $output->writeln('Could not comment on story ' . $storyId);
                 $output->writeln($ex->getResponse()->getBody(true), true);
             }
         }
     }
     $output->writeln('');
 }
开发者ID:BehalfFE,项目名称:git-log-version,代码行数:46,代码来源:CommentCommand.php

示例11: performRequest

 /**
  * {@inheritDoc}
  */
 public function performRequest($url, $parameters, $httpMethod = 'GET')
 {
     $request = $this->createRequest($url, $parameters, $httpMethod);
     try {
         $response = $this->client->send($request);
         return $response;
     } catch (\Imgur\Exception\LogicException $e) {
         error_log($e->getMessage());
     } catch (\Imgur\Exception\RuntimeException $e) {
         error_log($e->getMessage());
     } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {
         $responseData = $e->getResponse()->json();
         error_log('Request to: ' . $responseData['data']['request'] . ' failed with: [' . $responseData['status'] . ']"' . $responseData['data']['error'] . '"');
     } catch (Exception $e) {
         error_log($e->getMessage());
     }
     return false;
 }
开发者ID:billmalarky,项目名称:php-imgur-api-client,代码行数:21,代码来源:HttpClient.php

示例12:

 function it_sends_requests(HttpClient $http, UniqushRequest $uniqushRequest, RequestInterface $request, EntityBodyInterface $responseBody)
 {
     $uniqushRequest->getUrl()->willReturn('/push');
     $uniqushRequest->getQuery()->willReturn($query = ['service' => 'test', 'subscriber' => 'foo', 'msg' => 'bar']);
     $http->post('/push', [], $query)->shouldBeCalled()->willReturn($request);
     $http->send($request)->shouldBeCalled()->willReturn($responseBody);
     $responseBody->__toString()->willReturn('OK');
     $this->send($uniqushRequest)->shouldReturn('OK');
 }
开发者ID:desmart,项目名称:uniqush-client,代码行数:9,代码来源:ClientSpec.php

示例13: bulkPost

 /**
  * Call Guzzle Post request method
  *
  * @param  array $data Address data
  * @param  string $verb Method to be called - should only be geocode for now
  * @return Guzzle\Http\Message\Response
  */
 protected function bulkPost($data, $fields, $verb = 'geocode')
 {
     $url = self::BASE_URL . $verb . "?fields=" . implode(',', $fields) . "&api_key=" . $this->apiKey;
     $headers = ['Content-Type' => 'application/json'];
     $payload = json_encode($data);
     $request = $this->client->post($url, $headers, $payload, []);
     $response = $this->client->send($request);
     return $this->checkResponse($response);
 }
开发者ID:sumbudy,项目名称:geocodio-php,代码行数:16,代码来源:Client.php

示例14: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $label = $input->getArgument('label');
     $extractor = new StoriesExtractor();
     $storyIds = $extractor->collect();
     $client = new Client();
     $request = $client->createRequest('GET', 'https://www.pivotaltracker.com/services/v5/me', array('X-TrackerToken' => 'be17fcf368af9fa35cfe88b7460d2c67'));
     $response = $client->send($request);
     $this->projects = array_map(function ($item) {
         return $item['project_id'];
     }, json_decode($response->getBody(), true)['projects']);
     $labelsList = implode(',', $this->projects);
     $storyCount = count($storyIds);
     $output->writeln("Labeling {$storyCount} stories on projects {$labelsList}");
     foreach ($storyIds as $storyId) {
         foreach ($this->projects as $project) {
             $request = $client->createRequest('GET', "https://www.pivotaltracker.com/services/v5/projects/{$project}/stories/{$storyId}", ['X-TrackerToken' => 'be17fcf368af9fa35cfe88b7460d2c67']);
             //                $request->setHeader§('X-TrackerToken', 'be17fcf368af9fa35cfe88b7460d2c67');
             try {
                 $storyData = $client->send($request);
             } catch (ClientErrorResponseException $ex) {
                 continue;
             }
             $body = $storyData->getBody(true);
             $storyData = json_decode($body, true);
             $labels = $storyData['labels'];
             $labels[] = ['name' => $label];
             $request = $client->createRequest('PUT', "https://www.pivotaltracker.com/services/v5/projects/{$project}/stories/{$storyId}");
             $request->setHeader('X-TrackerToken', 'be17fcf368af9fa35cfe88b7460d2c67');
             $request->setHeader('Content-type', 'application/json');
             $request->setHeader('Accept', 'application/json');
             $request->setBody(json_encode(['labels' => $labels]));
             try {
                 $client->send($request);
                 $output->write('.');
                 break;
             } catch (ClientErrorResponseException $ex) {
                 $output->writeln('Could not label story ' . $storyId);
                 $output->writeln($ex->getResponse()->getBody(true), true);
             }
         }
     }
     $output->writeln('');
 }
开发者ID:BehalfFE,项目名称:git-log-version,代码行数:44,代码来源:LabelCommand.php

示例15: processRequest

 /**
  * @param GuzzleRequest $request
  * @return GuzzleRequest
  */
 private function processRequest(GuzzleRequest $request)
 {
     try {
         $response = $this->client->send($request);
     } catch (TransferException $e) {
         $json_exception = $e->getResponse()->json();
         HipChat::throwException($json_exception['error']['code'], $json_exception['error']['message'], $request->getUrl());
     }
     return $response;
 }
开发者ID:jfretin,项目名称:hipchat-php-v2,代码行数:14,代码来源:GuzzleV3.php


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