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


PHP RequestInterface::send方法代码示例

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


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

示例1: sendAndProcessResponse

 /**
  * @param RequestInterface $httpRequest
  * @return EchoResponse
  */
 private function sendAndProcessResponse(RequestInterface $httpRequest)
 {
     $httpResponse = $httpRequest->send();
     $data = $httpResponse->json();
     $response = new EchoResponse($this, $data);
     $response->setVerifier($this->getVerifier());
     return $response;
 }
开发者ID:bileto,项目名称:omnipay-csob,代码行数:12,代码来源:EchoRequest.php

示例2: sendRequest

 private function sendRequest(RequestInterface $request)
 {
     try {
         return $request->send();
     } catch (\Exception $e) {
         throw new GithubException('Unexpected response.', 0, $e);
     }
 }
开发者ID:mpscholten,项目名称:github-api,代码行数:8,代码来源:AbstractApi.php

示例3: request

 private function request(RequestInterface $request)
 {
     try {
         $response = $request->send();
     } catch (BadResponseException $e) {
         throw new Exception(sprintf('7digital API responded with an error %d.', $e->getResponse()->getStatusCode()), 0, $e);
     }
     return $this->getContent($response);
 }
开发者ID:gquemener,项目名称:7digital-client,代码行数:9,代码来源:Service.php

示例4: sendOAuth

 /**
  * @param RequestInterface $request
  * @return array|mixed
  */
 public function sendOAuth(RequestInterface $request)
 {
     try {
         $response = $request->send();
     } catch (ClientErrorResponseException $e) {
         return ["Error" => "Error:" . $e->getMessage()];
     }
     $return = json_decode($response->getBody(), true);
     if (array_key_exists("expires_in", $return)) {
         $return["expires_at"] = (int) (date("U") + $return["expires_in"]);
     }
     return $return;
 }
开发者ID:keldenar,项目名称:OAuth2,代码行数:17,代码来源:OAuth2.php

示例5: sendRequest

 /**
  * Sends a request
  *
  * @param RequestInterface $request
  * @return Response
  * @throws ForbiddenException
  * @throws MetricaException
  */
 protected function sendRequest(RequestInterface $request)
 {
     try {
         $request->setHeader('User-Agent', $this->getUserAgent());
         $response = $request->send();
     } catch (ClientErrorResponseException $ex) {
         $result = $request->getResponse();
         $code = $result->getStatusCode();
         $message = $result->getReasonPhrase();
         if ($code === 403) {
             throw new ForbiddenException($message);
         }
         throw new MetricaException('Service responded with error code: "' . $code . '" and message: "' . $message . '"');
     }
     return $response;
 }
开发者ID:silverslice,项目名称:yandex-php-library,代码行数:24,代码来源:MetricaClient.php

示例6: getCount

 /**
  * Get the issue count from the provided request.
  *
  *
  * @param array $request
  *   Guzzle request for the first page of results.
  * @return number
  *   The total number of issues for the search paramaters of the request.
  */
 public function getCount(\Guzzle\Http\Message\RequestInterface $request)
 {
     // Make sure page isn't set from a previous call on the same request object.
     $request->getQuery()->remove('page');
     $issueRowCount = 0;
     while (true) {
         $document = new DomCrawler\Crawler((string) $request->send()->getBody());
         $issueView = $document->filter('.view-project-issue-search-project-searchapi');
         $issueRowCount += $issueView->filter('table.views-table tbody tr')->reduce(function (DomCrawler\Crawler $element) {
             // Drupal.org is returning rows where all cells are empty,
             // which bumps up the count incorrectly.
             return $element->filter('td')->first()->filter('a')->count() > 0;
         })->count();
         $pagerNext = $issueView->filter('.pager-next a');
         if (!$pagerNext->count()) {
             break;
         }
         preg_match('/page=(\\d+)/', $pagerNext->attr('href'), $urlMatches);
         $request->getQuery()->set('page', (int) $urlMatches[1]);
     }
     return $issueRowCount;
 }
开发者ID:pingers,项目名称:drupalreleasedate,代码行数:31,代码来源:DrupalIssueCount.php

示例7: setResponse

 /**
  * Sets the response
  *
  * @param  RequestInterface $request
  * @return Response
  */
 protected function setResponse(RequestInterface $request)
 {
     try {
         $this->response = $request->send();
     } catch (ClientErrorResponseException $exception) {
         $this->response = $exception->getResponse();
         // @codeCoverageIgnoreStart
     } catch (ServerErrorResponseException $exception) {
         $this->response = $exception->getResponse();
     }
     // @codeCoverageIgnoreEnd
     return $this->response;
 }
开发者ID:lsv,项目名称:jwapi,代码行数:19,代码来源:Api.php

示例8: perform

 /**
  * Perform a http request and return the response
  *
  * @param \Guzzle\Http\Message\RequestInterface $request the request to preform
  * @param bool $async whether or not to perform an async request
  *
  * @return \Guzzle\Http\Message\Response|mixed the response from elastic search
  * @throws \Exception
  */
 public function perform(\Guzzle\Http\Message\RequestInterface $request, $async = false)
 {
     try {
         $profileKey = null;
         if ($this->enableProfiling) {
             $profileKey = __METHOD__ . '(' . $request->getUrl() . ')';
             if ($request instanceof \Guzzle\Http\Message\EntityEnclosingRequest) {
                 $profileKey .= " " . $request->getBody();
             }
             Yii::beginProfile($profileKey);
         }
         $response = $async ? $request->send() : json_decode($request->send()->getBody(true), true);
         Yii::trace("Sent request to '{$request->getUrl()}'", 'application.elastic.connection');
         if ($this->enableProfiling) {
             Yii::endProfile($profileKey);
         }
         return $response;
     } catch (\Guzzle\Http\Exception\BadResponseException $e) {
         $body = $e->getResponse()->getBody(true);
         if (($msg = json_decode($body)) !== null && isset($msg->error)) {
             throw new \CException($msg->error);
         } else {
             throw new \CException($e);
         }
     } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {
         throw new \CException($e->getResponse()->getBody(true));
     }
 }
开发者ID:Maxsh,项目名称:YiiElasticSearch,代码行数:37,代码来源:Connection.php

示例9: processRequest

 /**
  * Process request into a response object
  *
  * @param RequestInterface $request
  * @return \Guzzle\Http\Message\Response
  * @throws \Dlin\Zendesk\Exception\ZendeskException
  */
 public function processRequest(RequestInterface $request)
 {
     $response = $request->send();
     $attempt = 0;
     while ($response->getStatusCode() == 429 && $attempt < 5) {
         $wait = $response->getHeader('Retry-After');
         if ($wait > 0) {
             sleep($wait);
         }
         $attempt++;
         $response = $request->send();
     }
     if ($response->getStatusCode() >= 500) {
         throw new ZendeskException('Zendesk Server Error Detected.');
     }
     if ($response->getStatusCode() >= 400) {
         if ($response->getContentType() == 'application/json') {
             $result = $response->json();
             $description = array_key_exists($result, 'description') ? $result['description'] : 'Invalid Request';
             $value = array_key_exists($result, 'value') ? $result['value'] : array();
             $exception = new ZendeskException($description);
             $exception->setError($value);
             throw $exception;
         } else {
             throw new ZendeskException('Invalid API Request');
         }
     }
     return $response;
 }
开发者ID:nebijokit,项目名称:zendesk,代码行数:36,代码来源:BaseClient.php

示例10: exec

 private function exec(\Guzzle\Http\Message\RequestInterface $request)
 {
     $start = microtime(true);
     $this->responseCode = 0;
     // Get snapshot of request headers.
     $request_headers = $request->getRawHeaders();
     // Mask authorization for logs.
     $request_headers = preg_replace('!\\nAuthorization: (Basic|Digest) [^\\r\\n]+\\r!i', "\nAuthorization: \$1 [**masked**]\r", $request_headers);
     try {
         $response = $request->send();
     } catch (\Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
     } catch (\Guzzle\Http\Exception\CurlException $e) {
         // Timeouts etc.
         DebugData::$raw = '';
         DebugData::$code = $e->getErrorNo();
         DebugData::$code_status = $e->getError();
         DebugData::$code_class = 0;
         DebugData::$exception = $e->getMessage();
         DebugData::$opts = array('request_headers' => $request_headers);
         DebugData::$data = null;
         $exception = new ResponseException($e->getError(), $e->getErrorNo(), $request->getUrl(), DebugData::$opts);
         $exception->requestObj = $request;
         // Log Exception
         $headers_array = $request->getHeaders();
         unset($headers_array['Authorization']);
         $headerString = '';
         foreach ($headers_array as $value) {
             $headerString .= $value->getName() . ': ' . $value . " ";
         }
         $log_message = '{code_status} ({code}) Request Details:[ {r_method} {r_resource} {r_scheme} {r_headers} ]';
         $httpScheme = strtoupper(str_replace('https', 'http', $request->getScheme())) . $request->getProtocolVersion();
         $log_params = array('code' => $e->getErrorNo(), 'code_status' => $e->getError(), 'r_method' => $request->getUrl(), 'r_resource' => $request->getRawHeaders(), 'r_scheme' => $httpScheme, 'r_headers' => $headerString);
         self::$logger->emergency($log_message, $log_params);
         throw $exception;
     }
     $this->responseCode = $response->getStatusCode();
     $this->responseText = trim($response->getBody(true));
     $this->responseLength = $response->getContentLength();
     $this->responseMimeType = $response->getContentType();
     $this->responseObj = array();
     $content_type = $response->getContentType();
     $firstChar = substr($this->responseText, 0, 1);
     if (strpos($content_type, '/json') !== false && ($firstChar == '{' || $firstChar == '[')) {
         $response_obj = @json_decode($this->responseText, true);
         if (is_array($response_obj)) {
             $this->responseObj = $response_obj;
         }
     }
     $status = self::getStatusMessage($this->responseCode);
     $code_class = floor($this->responseCode / 100);
     DebugData::$raw = $this->responseText;
     DebugData::$opts = array('request_headers' => $request_headers, 'response_headers' => $response->getRawHeaders());
     if ($request instanceof \Guzzle\Http\Message\EntityEnclosingRequestInterface) {
         DebugData::$opts['request_body'] = (string) $request->getBody();
     }
     DebugData::$opts['request_type'] = class_implements($request);
     DebugData::$data = $this->responseObj;
     DebugData::$code = $this->responseCode;
     DebugData::$code_status = $status;
     DebugData::$code_class = $code_class;
     DebugData::$exception = null;
     DebugData::$time_elapsed = microtime(true) - $start;
     if ($code_class != 2) {
         $uri = $request->getUrl();
         if (!empty($this->responseCode) && isset($this->responseObj['message'])) {
             $message = 'Code: ' . $this->responseCode . '; Message: ' . $this->responseObj['message'];
         } else {
             $message = 'API returned HTTP code of ' . $this->responseCode . ' when fetching from ' . $uri;
         }
         DebugData::$exception = $message;
         $this->debugCallback(DebugData::toArray());
         self::$logger->error($this->responseText);
         // Create better status to show up in logs
         $status .= ': ' . $request->getMethod() . ' ' . $uri;
         if ($request instanceof \Guzzle\Http\Message\EntityEnclosingRequestInterface) {
             $body = $request->getBody();
             if ($body instanceof \Guzzle\Http\EntityBodyInterface) {
                 $status .= ' with Content-Length of ' . $body->getContentLength() . ' and Content-Type of ' . $body->getContentType();
             }
         }
         $exception = new ResponseException($status, $this->responseCode, $uri, DebugData::$opts, $this->responseText);
         $exception->requestObj = $request;
         $exception->responseObj = $response;
         throw $exception;
     }
     $this->debugCallback(DebugData::toArray());
 }
开发者ID:nevetS,项目名称:flame,代码行数:88,代码来源:APIObject.php

示例11: goslingResponse

 /**
  * Function saying according to the status code if the injection was a success or not
  * @param RequestInterface $req
  * @param $url
  * @return array
  * @internal param SqlTarget $target
  */
 public function goslingResponse(RequestInterface $req, $url)
 {
     $success = false;
     $res = $req->send();
     $status_code = $res->getStatusCode();
     if ($status_code == 200) {
         // Create a request that has a query string and an X-Foo header
         $request = $this->_guzzle->get($url);
         // Send the request and get the response
         $response = $request->send();
         // Connection to DB
         $repo = $this->_em->getRepository('AppBundle:HtmlError');
         $html_errors = $repo->findAll();
         foreach ($html_errors as $html_error) {
             if (preg_match($html_error->getValue(), $response->getBody(true))) {
                 $success = true;
             }
         }
     }
     $result = array("Success" => $success, "Status_code" => $status_code);
     return $result;
 }
开发者ID:haterecoil,项目名称:zerowing,代码行数:29,代码来源:SqlPentester.php

示例12: send

 /**
  * Send datas trough HTTP client
  *
  * @param HttpRequestInterface $request
  *
  * @param bool                 $stopOnException
  *
  * @return HttpResponse
  * @throws \Exception
  */
 protected function send(HttpRequestInterface $request, $stopOnException = false)
 {
     $request->setHeader('Content-Type', 'application/json')->setHeader('X-Auth-Token', array($this->token))->setHeader('X-Auth-UserId', array($this->userId));
     try {
         $response = $request->send();
     } catch (ClientErrorResponseException $e) {
         if (!$stopOnException && 401 == $e->getResponse()->getStatusCode() && null != $this->username) {
             // If the HTTP error is 401 Unauthorized, the session is cleared
             $username = $this->username;
             $password = $this->password;
             $this->clearSession();
             // Then we try a new authentication
             $this->getUserToken($username, $password);
             // Then we resend the request once
             $response = $this->send($request, true);
         } else {
             throw $e;
         }
     }
     if (!$response) {
         throw new \Exception(__NAMESPACE__ . '\\' . __CLASS__ . ' : Bad response while sending the request');
     }
     return $response;
 }
开发者ID:vmille,项目名称:TuleapRestApiBridge,代码行数:34,代码来源:Bridge.php

示例13: send

 private function send(RequestInterface $request)
 {
     try {
         $this->logger and $this->logger->debug(sprintf('%s "%s"', $request->getMethod(), $request->getUrl()));
         $this->logger and $this->logger->debug(sprintf("Request:\n%s", (string) $request));
         $response = $request->send();
         $this->logger and $this->logger->debug(sprintf("Response:\n%s", (string) $response));
         return $response;
     } catch (ClientErrorResponseException $e) {
         $this->logException($e);
         $this->processClientError($e);
     } catch (BadResponseException $e) {
         $this->logException($e);
         throw new ApiServerException('Something went wrong with upstream', 0, $e);
     }
 }
开发者ID:ftdysa,项目名称:insight,代码行数:16,代码来源:Api.php

示例14: sendRequest

 /**
  * Sends a request.
  *
  * @param \Guzzle\Http\Message\RequestInterface $request The request.
  *
  * @throws \Widop\HttpAdapter\HttpAdapterException If an error occured.
  *
  * @return \Widop\HttpAdapter\HttpResponse The response.
  */
 private function sendRequest(RequestInterface $request)
 {
     $request->getParams()->set('redirect.max', $this->getMaxRedirects());
     try {
         $response = $request->send();
     } catch (\Exception $e) {
         throw HttpAdapterException::cannotFetchUrl($request->getUrl(), $this->getName(), $e->getMessage());
     }
     return $this->createResponse($response->getStatusCode(), $request->getUrl(), $response->getHeaders()->toArray(), $response->getBody(true), $response->getEffectiveUrl());
 }
开发者ID:widop,项目名称:http-adapter,代码行数:19,代码来源:GuzzleHttpAdapter.php

示例15: request

 /**
  * @{inheritDoc}
  */
 public function request(RequestInterface $request)
 {
     $response = null;
     try {
         $response = $request->send();
     } catch (ClientErrorResponseException $e) {
         $error = $e->getResponse()->json();
         throw new TmdbApiException($error['status_message'], $error['status_code']);
     }
     $this->lastRequest = $request;
     $this->lastResponse = $response;
     return $response;
 }
开发者ID:n10ty,项目名称:api,代码行数:16,代码来源:HttpClient.php


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