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


PHP ClientInterface::request方法代码示例

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


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

示例1: loadSelf

 private function loadSelf()
 {
     if ($this->_client && $this->_links && isset($this->_links['self']) && isset($this->_links['self']['href'])) {
         $data = json_decode($this->_client->request('GET', $this->_links['self']['href'])->getBody(), true);
         $this->setFromApiData($data);
     }
 }
开发者ID:vierbergenlars,项目名称:authserver-client,代码行数:7,代码来源:LoadableTrait.php

示例2: callOpenpayClient

 /**
  * @param string $url
  * @param array $options
  * @param string $method
  * @return array
  * @throws OpenpayException
  */
 protected function callOpenpayClient($url, array $options, $method = self::GET_METHOD)
 {
     try {
         $rawResponse = $this->client->request($method, $url, $options);
     } catch (\Exception $e) {
         $responseParts = explode("\n", $e->getMessage());
         $openpayException = new OpenpayException($responseParts[0], $e->getCode(), $e);
         if (!is_null($e->getResponse())) {
             $headers = $e->getResponse()->getHeaders();
         }
         $values['error_code'] = isset($headers['OP-Error-Code']) ? $headers['OP-Error-Code'][0] : null;
         $values['request_id'] = isset($headers['OpenPay-Request-ID']) ? $headers['OpenPay-Request-ID'][0] : null;
         $dictionary = OpenpayExceptionsDictionary::get();
         if (isset($dictionary[$values['error_code']])) {
             $values['description'] = $dictionary[$values['error_code']][self::DESCRIPTION_DICTIONARY_KEY];
         }
         if (isset($responseParts[self::EXCEPTION_RESPONSE_JSON_INDEX])) {
             $responseObjectStr = $responseParts[self::EXCEPTION_RESPONSE_JSON_INDEX];
             $responseObject = json_decode($responseObjectStr, self::JSON_DECODE_TO_ARRAY);
             // sometimes openpay response is a malformed json
             if (json_last_error() === JSON_ERROR_NONE) {
                 $values = array_merge($values, $responseObject);
             }
             $openpayException = $this->exceptionMapper->create($values, $openpayException);
         }
         throw $openpayException;
     }
     $responseContent = $rawResponse->getBody()->getContents();
     $responseArray = json_decode($responseContent, self::JSON_DECODE_AS_ARRAY);
     return $responseArray;
 }
开发者ID:degaray,项目名称:openpay-php-client,代码行数:38,代码来源:OpenpayAdapterAbstract.php

示例3: sendRequest

 /**
  * Send request NIK
  *
  * @param  string $nik
  * @return \Psr\Http\Message\ResponseInterface
  * @throws \InvalidArgumentException
  * @throws \GuzzleHttp\Exception\GuzzleException
  */
 public function sendRequest($nik)
 {
     // Verify NIK
     $nik = $this->assertValidateNik($nik);
     $form_params = ['nik_global' => $nik, 'g-recaptcha-response' => ' ', 'wilayah_id' => '0', 'cmd' => 'Cari.'];
     return $this->client->request('POST', self::END_POINT, compact('form_params'));
 }
开发者ID:projek-xyz,项目名称:id-nik,代码行数:15,代码来源:Nik.php

示例4: sendRequest

 /**
  * @param string $method
  * @param string $endpoint
  * @param array $options
  * @return \stdClass
  */
 protected function sendRequest($method, $endpoint, array $options = [])
 {
     $this->assertHasAccessToken();
     $opts = array_merge_recursive(['headers' => ['Authorization' => 'Bearer ' . $this->accessToken]], $options);
     $res = $this->httpClient->request($method, self::API_URL . $endpoint, $opts);
     return json_decode((string) $res->getBody());
 }
开发者ID:VinniaAB,项目名称:social-tools,代码行数:13,代码来源:TwitterClient.php

示例5: fetch

 /**
  * Fetches data from api
  * @param string $url
  * @param array $options
  * @throws ConnectionException
  * @throws HTTPException
  * @return string
  */
 public function fetch($url, $options)
 {
     $request_type = $this->config->http_post === true ? 'form_params' : 'query';
     $options = [$request_type => $options];
     try {
         $response = $this->client->request($this->config->http_post === true ? 'POST' : 'GET', $url, $options);
     } catch (GuzzleException $exception) {
         throw new ConnectionException($exception->getMessage(), $exception->getCode());
     }
     if ($response->getStatusCode() >= 400) {
         // ccp is using error codes even if they send a valid application
         // error response now, so we have to use the content as result
         // for some of the errors. This will actually break if CCP ever uses
         // the HTTP Status for an actual transport related error.
         switch ($response->getStatusCode()) {
             case 400:
             case 403:
             case 500:
             case 503:
                 return $response->getBody()->getContents();
                 break;
         }
         throw new HTTPException($response->getStatusCode(), $url);
     }
     return $response->getBody()->getContents();
 }
开发者ID:addrever,项目名称:ecat,代码行数:34,代码来源:Guzzle.php

示例6: get

 public function get($url)
 {
     if (!$this->isValidArgument($url)) {
         throw new \InvalidArgumentException('Supply a valid URL please.');
     }
     return $this->guzzle->request("GET", $url);
 }
开发者ID:vinaykevadia,项目名称:moz,代码行数:7,代码来源:GuzzleClient.php

示例7: call

 /**
  * @param $id
  * @return Result
  */
 protected function call($method, $resource, $body = null, $acceptedCodes = array(200))
 {
     try {
         $response = $this->client->request($method, $resource, array('body' => $body));
         $responseBody = (string) $response->getBody();
         if ($responseBody) {
             /** @var Result $result */
             $result = $this->serializer->deserialize($responseBody, $this->getResultClass(), 'json');
             $result->deserializeData($this->serializer, $this->getModel());
         } else {
             $result = new Result();
         }
         $result->setSuccess(in_array($response->getStatusCode(), $acceptedCodes))->setMessage($response->getReasonPhrase());
         return $result;
     } catch (GuzzleException $ge) {
         if ($ge->getCode() == \Symfony\Component\HttpFoundation\Response::HTTP_TOO_MANY_REQUESTS && php_sapi_name() == "cli") {
             sleep(5);
             return $this->call($method, $resource, $body, $acceptedCodes);
         } else {
             $result = new Result();
             $result->setSuccess(false)->setMessage(sprintf("Client error: %s", $ge->getMessage()));
             return $result;
         }
     } catch (\Exception $e) {
         $result = new Result();
         $result->setSuccess(false)->setMessage(sprintf("General error: %s", $e->getMessage()));
         return $result;
     }
 }
开发者ID:progrupa,项目名称:MailjetBundle,代码行数:33,代码来源:AbstractApi.php

示例8:

 function it_should_get_a_raw_response(ClientInterface $handler, ResponseInterface $response)
 {
     $handler->request('GET', 'foo', [])->shouldBeCalled();
     $handler->request('GET', 'foo', [])->willReturn($response);
     $response->getBody()->shouldBeCalled();
     $this->get('foo', [], false);
 }
开发者ID:xotelia,项目名称:streak-php-client,代码行数:7,代码来源:ClientSpec.php

示例9: request

 /**
  * {@inheritDoc}
  */
 public function request($method, $uri, array $parameters = [])
 {
     $itemEnvelope = null;
     if (isset($parameters['itemEnvelope'])) {
         $itemEnvelope = $parameters['itemEnvelope'];
         unset($parameters['itemEnvelope']);
     }
     try {
         $response = $this->guzzle->request($method, $uri, array_merge($this->params, $parameters));
     } catch (ClientException $e) {
         if (!$e->hasResponse()) {
             throw $e;
         }
         throw $this->resolveExceptionClass($e);
     } catch (Exception $e) {
         throw $e;
     }
     $response = json_decode($response->getBody()->getContents(), true);
     if ($response === null) {
         $response = [];
     }
     if ($itemEnvelope) {
         $response['itemEnvelope'] = $itemEnvelope;
     }
     return Response::createFromJson($response);
 }
开发者ID:cleantekker,项目名称:php-sdk,代码行数:29,代码来源:GuzzleAdapter.php

示例10: send

 /**
  * @return TokenResponse
  */
 public function send()
 {
     $url = $this->serverConfig->getParams()['token_endpoint'];
     $params = [['name' => 'grant_type', 'contents' => self::GRANT_TYPE], ['name' => 'refresh_token', 'contents' => $this->refreshToken]];
     $response = $this->httpClient->request('POST', $url, ['multipart' => $params]);
     return new TokenResponse($response);
 }
开发者ID:easybiblabs,项目名称:oauth2-client-php,代码行数:10,代码来源:TokenRefreshRequest.php

示例11: it_includes_parameters

 public function it_includes_parameters(HttpClient $client, Response $response)
 {
     $url = 'http://www.example.com';
     $params = ['foo' => 'bar'];
     $client->request('get', $url, ['query' => $params])->shouldBeCalled();
     $client->request('get', $url, ['query' => $params])->willReturn($response);
     $this->get($url, $params)->shouldHaveType(GuzzleResponseAdapter::class);
 }
开发者ID:Zachu,项目名称:GizmoAPI,代码行数:8,代码来源:GuzzleClientAdapterSpec.php

示例12: request

 /**
  * Will perform a $verb request to the given $endpoint with $parameters.
  *
  * @param  string $endpoint   Url where curly braces will be replaces, Ex: add/{id}/something
  * @param  string $verb       May be get, delete, head, options, patch, post, put
  * @param  array  $parameters Array of parameters, Ex: ['id' => 5, 'name' => 'john doe']
  *
  * @throws RequestException
  *
  * @return array Response data
  */
 public function request($endpoint, $verb = 'get', array $parameters = [])
 {
     try {
         return $this->client->request($verb, $endpoint, $parameters);
     } catch (GuzzleException $error) {
         throw new RequestException((string) $error->getResponse()->getBody(), $error->getCode());
     }
 }
开发者ID:leroy-merlin-br,项目名称:exacttarget-client,代码行数:19,代码来源:RequestBuilder.php

示例13: getAccessToken

 /**
  * @param string $apiKey
  * @param string $apiSecret
  * @param string $username
  * @param string $password
  * 
  * @return AccessToken
  */
 public function getAccessToken($apiKey, $apiSecret, $username, $password)
 {
     $response = $this->guzzle->request('POST', self::ENDPOINT, ['auth' => [$apiKey, $apiSecret], 'form_params' => ['grant_type' => 'password', 'username' => $username, 'password' => $password]]);
     $data = json_decode((string) $response->getBody(), true);
     $token = $data['access_token'];
     $expiry = new \DateTime('@' . (time() + $data['expires_in']));
     return new AccessToken($token, $expiry);
 }
开发者ID:moneymaxim,项目名称:TrustpilotAuthenticator,代码行数:16,代码来源:Authenticator.php

示例14: __call

 /**
  * Calls the method contained in the actions of this resource
  * @param string $method
  * @param array $args
  * @return \StdClass The JSON decoded response
  */
 public function __call($method, $args)
 {
     $action = $this->getActions()[$method];
     $uri = $this->getBaseUri() . $this->getPath($action, $args);
     $params = $this->getParams($args);
     $this->last_response = $this->client->request($action['method'], $uri, $params);
     return json_decode($this->last_response->getBody());
 }
开发者ID:DennyLoko,项目名称:snorlax,代码行数:14,代码来源:Resource.php

示例15: request

 /**
  * Perform the HTTP request
  *
  * @param  string $method     HTTP method/verb
  * @param  string $url        URL to send the request
  * @param  array  $parameters Key/Value pairs to form the query string
  * @param  array  $options    Options to pass straight to GuzzleClient
  *
  * @return \Pisa\GizmoAPI\Adapters\GuzzleResponseAdapter
  */
 public function request($method, $url, array $parameters = [], array $options = [])
 {
     if (!empty($parameters)) {
         $options['query'] = $this->fixParameters($parameters);
     }
     $response = $this->client->request($method, $url, $options);
     return new HttpResponse($response);
 }
开发者ID:Zachu,项目名称:GizmoAPI,代码行数:18,代码来源:GuzzleClientAdapter.php


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