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


PHP ClientInterface::send方法代码示例

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


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

示例1: fetch

 /**
  * {@inheritdoc}
  */
 public function fetch(FeedInterface $feed)
 {
     $request = $this->httpClient->createRequest('GET', $feed->getUrl());
     $feed->source_string = FALSE;
     // Generate conditional GET headers.
     if ($feed->getEtag()) {
         $request->addHeader('If-None-Match', $feed->getEtag());
     }
     if ($feed->getLastModified()) {
         $request->addHeader('If-Modified-Since', gmdate(DateTimePlus::RFC7231, $feed->getLastModified()));
     }
     try {
         $response = $this->httpClient->send($request);
         // In case of a 304 Not Modified, there is no new content, so return
         // FALSE.
         if ($response->getStatusCode() == 304) {
             return FALSE;
         }
         $feed->source_string = $response->getBody(TRUE);
         $feed->setEtag($response->getHeader('ETag'));
         $feed->setLastModified(strtotime($response->getHeader('Last-Modified')));
         $feed->http_headers = $response->getHeaders();
         // Update the feed URL in case of a 301 redirect.
         if ($response->getEffectiveUrl() != $feed->getUrl()) {
             $feed->setUrl($response->getEffectiveUrl());
         }
         return TRUE;
     } catch (RequestException $e) {
         $this->logger->warning('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage()));
         drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage())), 'warning');
         return FALSE;
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:36,代码来源:DefaultFetcher.php

示例2: send

 /**
  * @param \DonePM\ConsoleClient\Http\Commands\Command $command
  *
  * @return mixed|\Psr\Http\Message\ResponseInterface
  */
 public function send(Command $command)
 {
     if ($command instanceof NeedsToken) {
         $command->token($this->token);
     }
     return $this->client->send($command->request());
 }
开发者ID:donepm,项目名称:cli-client,代码行数:12,代码来源:Client.php

示例3: testOnlyResponse

 public function testOnlyResponse()
 {
     $request = $this->guzzleHttpClient->createRequest('GET', 'http://petstore.swagger.io/v2/pet/findByStatus');
     $request->addHeader('Accept', 'application/json');
     $response = $this->guzzleHttpClient->send($request);
     $this->assertResponseMatch($response, self::$schemaManager, '/v2/pet/findByStatus', 'get');
 }
开发者ID:Beanhunter,项目名称:SwaggerAssertions,代码行数:7,代码来源:GuzzleTest.php

示例4: sendPostRequest

 /**
  * @param string $url
  * @param mixed[]|null $body
  * @return \SlevomatZboziApi\Response\ZboziApiResponse
  */
 public function sendPostRequest($url, array $body = null)
 {
     TypeValidator::checkString($url);
     $options = ['allow_redirects' => false, 'verify' => true, 'decode_content' => true, 'expect' => false, 'timeout' => $this->timeoutInSeconds];
     $request = $this->client->createRequest('POST', $url, $options);
     $request->setHeaders([static::HEADER_PARTNER_TOKEN => $this->partnerToken, static::HEADER_API_SECRET => $this->apiSecret]);
     if ($body !== null) {
         $request->setBody(\GuzzleHttp\Stream\Stream::factory(json_encode($body)));
     }
     try {
         try {
             $response = $this->client->send($request);
             $this->log($request, $response);
             return $this->getZboziApiResponse($response);
         } catch (\GuzzleHttp\Exception\RequestException $e) {
             $response = $e->getResponse();
             $this->log($request, $response);
             if ($response !== null) {
                 return $this->getZboziApiResponse($response);
             }
             throw new \SlevomatZboziApi\Request\ConnectionErrorException('Connection to Slevomat API failed.', $e->getCode(), $e);
         }
     } catch (\GuzzleHttp\Exception\ParseException $e) {
         $this->log($request, isset($response) ? $response : null, true);
         throw new \SlevomatZboziApi\Response\ResponseErrorException('Slevomat API invalid response: invalid JSON data.', $e->getCode(), $e);
     }
 }
开发者ID:pepakriz,项目名称:zbozi-api-php-library,代码行数:32,代码来源:RequestMaker.php

示例5: handleRequest

 protected function handleRequest(Request $request)
 {
     if (!isset($this->config['batch'])) {
         return $this->client->send($request);
     }
     return $request;
 }
开发者ID:vdbf,项目名称:magento-rest-php,代码行数:7,代码来源:Connector.php

示例6: sendAsync

 /**
  * Send asynchronous guzzle request
  *
  * @param RequestInterface $psrRequest
  * @param \Tebru\Retrofit\Http\Callback $callback
  * @return null
  */
 public function sendAsync(RequestInterface $psrRequest, Callback $callback)
 {
     $request = $this->createRequest($psrRequest, true);
     /** @var FutureInterface $response */
     $response = $this->client->send($request);
     $response->then(function (ResponseInterface $response) {
         return new Psr7Response($response->getStatusCode(), $response->getHeaders(), $response->getBody(), $response->getProtocolVersion(), $response->getReasonPhrase());
     }, function (Exception $exception) use($callback, $psrRequest) {
         $request = $psrRequest;
         $response = null;
         if ($exception instanceof \GuzzleHttp\Exception\RequestException) {
             $request = $exception->getRequest();
             $response = $exception->getResponse();
         }
         $requestException = new RequestException($exception->getMessage(), $exception->getCode(), $exception->getPrevious(), $request, $response);
         if (null !== $this->eventDispatcher) {
             $this->eventDispatcher->dispatch(ApiExceptionEvent::NAME, new ApiExceptionEvent($requestException, $request));
         }
         $callback->onFailure($requestException);
     })->then(function (Psr7Response $response) use($callback, $psrRequest) {
         if (null !== $this->eventDispatcher) {
             $this->eventDispatcher->dispatch(AfterSendEvent::NAME, new AfterSendEvent($psrRequest, $response));
         }
         $callback->onResponse($response);
     });
     $this->responses[] = $response;
 }
开发者ID:tebru,项目名称:retrofit-http-clients,代码行数:34,代码来源:GuzzleV5ClientAdapter.php

示例7: send

 /**
  * @param TransportRequestInterface $request The configured request to send.
  *
  * @throws \Elastification\Client\Exception\ClientException
  * @return \Elastification\Client\Transport\TransportResponseInterface
  * @author Mario Mueller
  */
 public function send(TransportRequestInterface $request)
 {
     try {
         return new GuzzleTransportResponse($this->guzzleClient->send($request->getWrappedRequest()));
     } catch (\Exception $exception) {
         throw new TransportLayerException($exception->getMessage(), $exception->getCode(), $exception);
     }
 }
开发者ID:thebennos,项目名称:php-client,代码行数:15,代码来源:GuzzleTransport.php

示例8:

 function it_should_post_an_url(ClientInterface $handler, RequestInterface $request, ResponseInterface $response)
 {
     $options = ['body' => 'foo'];
     $handler->createRequest('POST', 'foo', $options)->willReturn($request);
     $handler->send($request)->shouldBeCalled();
     $handler->send($request)->willReturn($response);
     $this->post('foo', $options);
 }
开发者ID:xotelia,项目名称:xotelia-php-client,代码行数:8,代码来源:ClientSpec.php

示例9: testFetchPetBodyMatchDefinition

 public function testFetchPetBodyMatchDefinition()
 {
     $request = $this->guzzleHttpClient->createRequest('GET', 'http://petstore.swagger.io/v2/pet/findByStatus');
     $request->addHeader('Accept', 'application/json');
     $response = $this->guzzleHttpClient->send($request);
     $responseBody = $response->json(['object' => true]);
     $this->assertResponseBodyMatch($responseBody, self::$schemaManager, '/v2/pet/findByStatus', 'get', 200);
 }
开发者ID:Beanhunter,项目名称:SwaggerAssertions,代码行数:8,代码来源:LocalFileTest.php

示例10: get

 /**
  * @param $url
  * @param array $params
  *
  * @return array
  */
 public function get($url, $params = array())
 {
     $request = $this->provider->request($url, $params);
     $response = $this->client->send($request);
     $data = $response->getBody()->getContents();
     $format = $this->getFormat($params, $response);
     return $this->serializer->deserialize($data, null, $format);
 }
开发者ID:bangpound,项目名称:oembed,代码行数:14,代码来源:Consumer.php

示例11: sendRequest

 /**
  * {@inheritdoc}
  */
 public function sendRequest(RequestInterface $request)
 {
     try {
         return $this->client->send($request);
     } catch (RequestException $e) {
         throw $this->createException($e);
     }
 }
开发者ID:Nyholm,项目名称:guzzle6-adapter,代码行数:11,代码来源:Guzzle6HttpAdapter.php

示例12: perform

 /**
  * {@inheritdoc}
  */
 public function perform(OperationInterface $operation, ConfigurationInterface $configuration)
 {
     $preparedRequestParams = $this->prepareRequestParams($operation, $configuration);
     $queryString = $this->buildQueryString($preparedRequestParams, $configuration);
     $uri = new Uri(sprintf($this->requestTemplate, $configuration->getCountry(), $queryString));
     $request = new \GuzzleHttp\Psr7\Request('GET', $uri->withScheme($this->scheme), ['User-Agent' => 'ApaiIO [' . ApaiIO::VERSION . ']']);
     $result = $this->client->send($request);
     return $result->getBody()->getContents();
 }
开发者ID:exeu,项目名称:apai-io,代码行数:12,代码来源:GuzzleRequest.php

示例13: handle

 /**
  * {@inheritdoc}
  */
 public function handle(RequestInterface $request)
 {
     $guzzleRequest = $this->createGuzzleRequestFromRequest($request);
     // @todo add support for exceptions
     $guzzleResponse = $this->client->send($guzzleRequest);
     /** @var \GuzzleHttp\Message\Response $guzzleResponse */
     $response = $this->createResponseFromGuzzleResponse($guzzleResponse);
     return $response;
 }
开发者ID:phpextra,项目名称:proxy,代码行数:12,代码来源:Guzzle4Adapter.php

示例14: sendAsync

 /**
  * Send asynchronous guzzle request
  *
  * @param Psr7Request $request
  * @param \Tebru\Retrofit\Http\Callback $callback
  * @return null
  */
 public function sendAsync(Psr7Request $request, Callback $callback)
 {
     $request = new Request($request->getMethod(), (string) $request->getUri(), $request->getHeaders(), $request->getBody(), ['future' => true]);
     /** @var FutureInterface $response */
     $response = $this->client->send($request);
     $this->promises[] = $response->then(function (ResponseInterface $response) {
         return new Psr7Response($response->getStatusCode(), $response->getHeaders(), $response->getBody(), $response->getProtocolVersion(), $response->getReasonPhrase());
     })->then($callback->success(), $callback->failure());
 }
开发者ID:epfremmer,项目名称:retrofit-http-clients,代码行数:16,代码来源:GuzzleV5ClientAdapter.php

示例15: request

 /**
  * @inheritdoc
  */
 public function request(Client $client)
 {
     $tokenUrl = $client->getTokenUrl();
     $queryData = ["client_id" => $client->getClientId(), "client_secret" => $client->getClientSecret(), "grant_type" => "client_credentials"];
     $url = $tokenUrl . "?" . http_build_query($queryData);
     $request = new Request("GET", $url);
     $response = $this->httpClient->send($request);
     return $response;
 }
开发者ID:koenreiniers,项目名称:oauth-client-bundle,代码行数:12,代码来源:ClientCredentialsGrant.php


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