本文整理汇总了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);
}
}
示例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;
}
示例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());
}
示例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();
}
}
示例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;
}
示例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()}");
}
}
示例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;
}
示例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();
}
示例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)));
}
示例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('');
}
示例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;
}
示例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');
}
示例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);
}
示例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('');
}
示例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;
}