本文整理汇总了PHP中GuzzleHttp\Client::send方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::send方法的具体用法?PHP Client::send怎么用?PHP Client::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Client
的用法示例。
在下文中一共展示了Client::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doRequest
/**
* @return array
*/
public function doRequest() : array
{
$this->generateRequestOptions();
$this->authenticator->authenticate($this);
$request = $this->httpClient->createRequest($this->method, $this->getUrl(), $this->requestOptions);
return $this->httpClient->send($request)->json();
}
示例2: getResponse
/**
* Get the result of the http request.
*
* @return Response
*/
protected function getResponse()
{
if ($this->response === null) {
$this->response = $this->client->send($this->request);
}
return $this->response;
}
示例3: subscribe
/**
* Method to handle the Subscribe Request to the Hub
*/
public function subscribe()
{
// Start empty $hubUrl variable
$hubUrl = '';
// Check if the Hub URL finishes with a / or not to be able to create the correct subscribe URL
if (preg_match("/\\/\$/", $this->current_options['hub_url'])) {
$hubUrl = $this->current_options['hub_url'] . 'subscribe';
} else {
$hubUrl = $this->current_options['hub_url'] . '/subscribe';
}
// Json Data needed to send to the Hub for Subscription
$subscribeJson = json_encode(array("callbackUrl" => esc_url($this->callbackUrl), "topicId" => esc_url($this->current_options['topic_url'])), JSON_UNESCAPED_SLASHES);
$subscribeRequest = $this->guzzleClient->createRequest('POST', $hubUrl);
$subscribeRequest->setHeader('Content-Type', 'application/json');
$subscribeRequest->setBody(Stream::factory($subscribeJson));
$subscribeResponse = $this->guzzleClient->send($subscribeRequest);
// Check if Response is 200, 202 or 204 and add a log message otherwise log error message
if (in_array($subscribeResponse->getStatusCode(), array(200, 202, 204))) {
HubLogger::log('Your Subscription request is being processed. Check back later to see if you are fully Subscribed', $subscribeResponse->getStatusCode());
return true;
} else {
HubLogger::error('Error issuing Subscribe request to the Hub. Please make sure all your details are correct', $subscribeResponse->getStatusCode());
return false;
}
}
示例4: 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());
}
示例5: request
/**
* @param string $method
* @param string $uri
* @param array $options
*
* @return ResponseInterface
*/
public function request($method, $uri, array $options = [])
{
$this->lazyLoadGuzzle();
$this->lastRequest = $this->guzzle->createRequest($method, $uri, $options);
$response = $this->guzzle->send($this->lastRequest);
return $response;
}
示例6: get
/**
* @param string $path
* @param array $queryParams
*
* @return \StdClass
*
* @throws RequestException
*/
private function get($path, array $queryParams = array())
{
$url = self::BASE_URI . $path;
$request = $this->createHttpRequest('GET', $url, $queryParams);
$response = $this->httpClient->send($request);
return $this->parseResponse($response);
}
示例7: request
/**
* @param Request $request
* @return Response
*/
public function request(Request $request)
{
$guzzleRequest = $this->prepareRequest($request);
/** @var GuzzleResponse $guzzleResponse */
$guzzleResponse = $this->client->send($guzzleRequest);
return new Response($guzzleResponse->getProtocolVersion(), (int) $guzzleResponse->getStatusCode(), $guzzleResponse->getReasonPhrase(), HeaderConverter::convertComplexAssociativeToFlatAssociative($guzzleResponse->getHeaders()), (string) $guzzleResponse->getBody());
}
示例8: send
/**
* Send the request and return the response.
*
* @param Request $request
* @param string $url
* @return Response
*/
public function send(Request $request, $url)
{
$guzzleRequest = $this->convertRequest($request);
$guzzleRequest->setUrl($url);
$guzzleResponse = $this->client->send($guzzleRequest);
return $this->convertResponse($guzzleResponse);
}
示例9: testItIsNotStupid
/**
* @param Request $request
*
* @dataProvider nonCachableRequestProvider
*/
public function testItIsNotStupid(Request $request)
{
$this->client->send($request);
// Will not be cached
$response = $this->client->send($request);
// Will not come from cache
$this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
}
示例10: sendGuzzleRequest
protected function sendGuzzleRequest($http_verb = 'GET', $url, $data = null)
{
if (date(time()) >= Session::get('oauth_token_expiry')) {
$this->refreshAccessToken();
}
$request = $this->client->createRequest($http_verb, $url, ['json' => $data, 'headers' => ['Authorization' => 'Bearer ' . Session::get('access_token')]]);
return $this->client->send($request)->json();
}
示例11: sendRequest
/**
* Send a request and convert any BadResponseExceptions to a RequestException
*
* @param \GuzzleHttp\Psr7\Request $request
* @return \Psr\Http\Message\ResponseInterface
* @throws Exception\RequestException
*/
protected function sendRequest(Request $request)
{
try {
return $this->http_client->send($request);
} catch (ClientException $e) {
throw new Exception\RequestException($e);
}
}
示例12: execute
public function execute($method, $uri, $data)
{
$request = $this->guzzleClient->createRequest($method, $uri, $data);
/** @var ResponseInterface $response */
/** @noinspection PhpVoidFunctionResultUsedInspection */
$response = $this->guzzleClient->send($request);
return new Response($response);
}
示例13: broadcast
/**
* Broadcast the given event.
*
* @param array $channels
* @param string $event
* @param array $payload
* @return void
*/
public function broadcast(array $channels, $event, array $payload = array())
{
foreach ($channels as $channel) {
$payload = ['text' => array_merge(['eventtype' => $event], $payload)];
$request = $this->client->createRequest('POST', '/pub?id=' . $channel, ['json' => $payload]);
$response = $this->client->send($request);
}
}
示例14: send
/**
* @inheritDoc
*
* @param RequestInterface $request request
*
* @return ResponseInterface
*/
public function send(RequestInterface $request)
{
$options = array('curl' => []);
foreach ($this->curlOptions as $option => $value) {
$options['curl'][constant('CURLOPT_' . strtoupper($option))] = $value;
}
$options['verify'] = __DIR__ . '/../../Resources/cert/cacert.pem';
return $this->client->send($request, $options);
}
示例15: send
/**
* @param \Psr\Http\Message\RequestInterface $request
* @param array $options
*
* @throws \Spryker\Zed\Payolution\Business\Exception\ApiHttpRequestException
*
* @return string
*/
protected function send($request, array $options = [])
{
try {
$response = $this->client->send($request, $options);
} catch (RequestException $requestException) {
throw new ApiHttpRequestException($requestException->getMessage());
}
return $response->getBody();
}