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


PHP Request::send方法代码示例

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


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

示例1: doHealthCheck

 /**
  * Actual health check logic.
  *
  * @param HealthBuilder $builder
  *
  * @throws \Exception any Exception that should create a Status::DOWN
  *                    system status.
  */
 protected function doHealthCheck(HealthBuilder $builder)
 {
     /** @var Response $response */
     $response = $this->request->send();
     $builder->withDetail('statusCode', $response->getStatusCode());
     if (!$response->isSuccessful()) {
         $builder->down()->withDetail('body', $response->getBody(true));
         return;
     }
     $builder->up();
 }
开发者ID:postalservice14,项目名称:php-actuator,代码行数:19,代码来源:GuzzleRequestHealthIndicator.php

示例2: proceedResponse

 /**
  * @param Request $request
  * @return array|null
  * @throws BadResponseException
  * @throws FormatException
  */
 protected function proceedResponse(Request $request)
 {
     try {
         $response = $request->send();
     } catch (ClientErrorResponseException $e) {
         $response = $e->getResponse();
     }
     $body = $response->getBody(true);
     if (empty($body) && $response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
         return null;
     }
     $result = json_decode($body, true);
     if ($result === null) {
         # When response is just a sting.
         $result = $body;
     }
     if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
         return $result;
     }
     if (!$result || !$result['error']) {
         throw new FormatException('Not valid error response', 3, null, $request, $response);
     }
     $message = $result['error']['message'];
     $code = $result['error']['code'];
     if ($response->getStatusCode() == 429) {
         throw new RateLimitException($message, $code, null, $request, $response);
     }
     $e = new BadResponseException($message, $code, null, $request, $response);
     $e->setError($result['error']);
     throw $e;
 }
开发者ID:yuri-sagalovich,项目名称:nextcaller-php-api,代码行数:37,代码来源:NextCallerBaseClient.php

示例3: resolveRequest

 private function resolveRequest(\Guzzle\Http\Message\Request $request)
 {
     try {
         $this->lastResponse = $request->send();
     } catch (\Guzzle\Http\Exception\TooManyRedirectsException $tooManyRedirectsException) {
         if ($this->hasRequestHistory($request)) {
             $this->lastResponse = $this->getRequestHistory($request)->getLastResponse();
         } else {
             return $request->getUrl();
         }
     } catch (\Guzzle\Http\Exception\BadResponseException $badResponseException) {
         if ($this->getConfiguration()->getRetryWithUrlEncodingDisabled() && !$this->getConfiguration()->getHasRetriedWithUrlEncodingDisabled()) {
             $this->getConfiguration()->setHasRetriedWithUrlEncodingDisabled(true);
             return $this->resolveRequest($this->deEncodeRequestUrl($request));
         } else {
             $this->lastResponse = $badResponseException->getResponse();
         }
     }
     if ($this->getConfiguration()->getHasRetriedWithUrlEncodingDisabled()) {
         $this->getConfiguration()->setHasRetriedWithUrlEncodingDisabled(false);
     }
     if ($this->getConfiguration()->getFollowMetaRedirects()) {
         $metaRedirectUrl = $this->getMetaRedirectUrlFromLastResponse();
         if (!is_null($metaRedirectUrl) && !$this->isLastResponseUrl($metaRedirectUrl)) {
             return $this->resolve($metaRedirectUrl);
         }
     }
     return $this->lastResponse->getEffectiveUrl();
 }
开发者ID:webignition,项目名称:url-resolver,代码行数:29,代码来源:Resolver.php

示例4: sendRequest

 /**
  * Function to send the request to the remote API
  *
  * @return  \Trucker\Responses\Response
  */
 public function sendRequest()
 {
     try {
         $response = $this->request->send();
     } catch (\Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
     }
     return $this->app->make('trucker.response')->newInstance($this->app, $response);
 }
开发者ID:summer11123,项目名称:trucker,代码行数:14,代码来源:RestRequest.php

示例5: request

 public function request(Request $request)
 {
     try {
         $response = $request->send();
     } catch (\Exception $e) {
         throw new ApiException($e->getMessage(), $e->getCode(), $e);
     }
     $apiResponse = new ApiResponse($response->getBody(), $response->getStatusCode(), $response->getContentType());
     return $apiResponse;
 }
开发者ID:spiasecki,项目名称:ubirimi,代码行数:10,代码来源:GuzzleClientAdapter.php

示例6: send

 public function send()
 {
     try {
         return parent::send();
     } catch (BadResponseException $e) {
         $response = $e->getResponse();
         $data = json_decode($response->getBody());
         throw new GroongaException($data[0][3]);
     }
 }
开发者ID:nise-nabe,项目名称:groonga-http-php,代码行数:10,代码来源:GroongaRequest.php

示例7: testMagicOperationsReturnResult

 /**
  * Executing service description defined operations returns the result
  * @group unit
  */
 public function testMagicOperationsReturnResult()
 {
     $responseData = array("this" => "that");
     Phockito::when($this->mockResponse->getStatusCode())->return(200);
     Phockito::when($this->mockResponse->json())->return($this->testDescription);
     Phockito::when($this->mockRequest->send())->return($this->mockResponse);
     Phockito::when($this->client)->get(anything())->return($this->mockRequest);
     Phockito::when($this->client)->callParent(anything(), anything())->return($responseData);
     $result = $this->client->SomeOperation(array());
     $this->assertEquals($result, $responseData);
 }
开发者ID:balihoo,项目名称:publish-service-client,代码行数:15,代码来源:ClientTest.php

示例8: testRequestThrowsExceptionOnBadResponse

 /**
  * @covers Guzzle\Http\Message\Request::getResponse
  * @covers Guzzle\Http\Message\Request::processResponse
  * @covers Guzzle\Http\Message\Request::getResponseBody
  */
 public function testRequestThrowsExceptionOnBadResponse()
 {
     try {
         $this->request->setResponse(new Response(404, array('Content-Length' => 3), 'abc'), true);
         $this->request->send();
         $this->fail('Expected exception not thrown');
     } catch (BadResponseException $e) {
         $this->assertInstanceOf('Guzzle\\Http\\Message\\RequestInterface', $e->getRequest());
         $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $e->getResponse());
         $this->assertContains('Client error response', $e->getMessage());
     }
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:17,代码来源:RequestTest.php

示例9: loadSource

 /**
  * Load request sources
  *
  * @param $source
  * @return Export
  */
 public function loadSource($source = '')
 {
     empty($source) === false ? $this->setSource($source) : null;
     $client = new Client($this->source, $this->options);
     $this->request = $client->createRequest();
     try {
         $this->response = $this->request->send();
     } catch (ResponseException $e) {
         throw new BadResponseException($e->getMessage(), $e->getCode());
     }
     return $this;
 }
开发者ID:stanislav-web,项目名称:catalogue-export,代码行数:18,代码来源:Export.php

示例10: sendRequest

 /**
  * Function to send the request to the remote API
  *
  * @return  \Trucker\Responses\Response
  */
 public function sendRequest()
 {
     try {
         $response = $this->request->send();
     } catch (\Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
     }
     if (Config::get('request.debug', false)) {
         echo 'Request Method: ' . $this->request->getMethod() . "\n";
         echo "Body: " . $response->getBody() . "\n";
         echo "Status Code: " . $response->getStatusCode() . "\n";
         echo "URL: " . $this->request->getUrl() . "\n\n";
     }
     return $this->app->make('trucker.response')->newInstance($this->app, $response);
 }
开发者ID:victormacko,项目名称:trucker,代码行数:20,代码来源:RestRequest.php

示例11: send

 /**
  * @return \Sokil\Rest\Client\Response
  */
 public function send()
 {
     try {
         // disbatch beforeSend event
         $this->_request->getEventDispatcher()->dispatch('onBeforeSend', new \Guzzle\Common\Event(array('request' => $this)));
         // create response
         $this->_response = new Response($this->_request->send(), $this->_structureClassName);
         // trigger event
         $this->_request->getEventDispatcher()->dispatch('onParseResponse', new \Guzzle\Common\Event(array('request' => $this, 'response' => $this->_response)));
         // log
         if ($this->hasLogger()) {
             $this->getLogger()->debug((string) $this->_request . PHP_EOL . (string) $this->_request->getResponse());
         }
         return $this->_response;
     } catch (\Exception $e) {
         if ($this->hasLogger()) {
             $this->getLogger()->debug((string) $e);
         }
         throw $e;
     }
 }
开发者ID:sokil,项目名称:php-rest,代码行数:24,代码来源:Request.php

示例12: iRequest

 /**
  * @When /^I request "(GET|PUT|POST|DELETE|PATCH) ([^"]*)"$/
  */
 public function iRequest($httpMethod, $resource)
 {
     // process any %battles.last.id% syntaxes
     $resource = $this->processReplacements($resource);
     $this->resource = $resource;
     // reset the response payload
     $this->responsePayload = null;
     $method = strtolower($httpMethod);
     try {
         switch ($httpMethod) {
             case 'PUT':
             case 'POST':
             case 'PATCH':
                 // process any %user.weaverryan.id% syntaxes
                 $payload = $this->processReplacements($this->requestPayload);
                 $this->lastRequest = $this->client->{$method}($resource, null, $payload);
                 break;
             default:
                 $this->lastRequest = $this->client->{$method}($resource);
         }
         if ($this->authUser) {
             $this->lastRequest->setAuth($this->authUser, $this->authPassword);
         }
         foreach ($this->headers as $key => $val) {
             $this->lastRequest->setHeader($key, $val);
         }
         $this->response = $this->lastRequest->send();
     } catch (BadResponseException $e) {
         $response = $e->getResponse();
         // Sometimes the request will fail, at which point we have
         // no response at all. Let Guzzle give an error here, it's
         // pretty self-explanatory.
         if ($response === null) {
             throw $e;
         }
         $this->response = $e->getResponse();
     }
 }
开发者ID:rllmwm,项目名称:forbiddencat,代码行数:41,代码来源:ApiFeatureContext.php

示例13: send

 /**
  * @param \Guzzle\Http\Message\Request $request
  * @return \Guzzle\Http\Message\Response
  */
 public function send(\Guzzle\Http\Message\Request $request)
 {
     $token = $this->getToken();
     $request->setHeader('X-Auth-Token', $token['token'])->setHeader('Content-Type', 'application/json')->setHeader('X-Auth-UserId', $token['user_id']);
     return $request->send();
 }
开发者ID:pombredanne,项目名称:tuleap,代码行数:10,代码来源:Request.php

示例14: post

 /**
  * @param string $uri
  * @param array $headers
  * @param string $postBody
  * @param array $options
  * @return array|\Guzzle\Http\Message\Response
  */
 public function post($uri, $headers = [], $postBody = null, $options = [])
 {
     $this->request = $this->client->post($uri, $headers, $postBody, $options);
     $this->response = $this->request->send();
     return $this->response;
 }
开发者ID:chilimatic,项目名称:database-component,代码行数:13,代码来源:Connection.php

示例15: getResponse

 /**
  * Get the response from the prepared request.
  *
  * @param \Guzzle\Http\Message\Request $request
  *
  * @return array
  */
 protected function getResponse($request)
 {
     try {
         $response = json_decode($request->send()->getBody(), true);
         return $response['response'];
     } catch (BadResponseException $bre) {
         return;
     }
 }
开发者ID:phpspider,项目名称:laravel-tricks,代码行数:16,代码来源:Disqus.php


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