本文整理汇总了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;
}
}
示例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());
}
示例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');
}
示例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);
}
}
示例5: handleRequest
protected function handleRequest(Request $request)
{
if (!isset($this->config['batch'])) {
return $this->client->send($request);
}
return $request;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例11: sendRequest
/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request)
{
try {
return $this->client->send($request);
} catch (RequestException $e) {
throw $this->createException($e);
}
}
示例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();
}
示例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;
}
示例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());
}
示例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;
}