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


PHP RequestInterface::getBody方法代码示例

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


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

示例1: formatBody

 /**
  * @param RequestInterface|ResponseInterface $message
  * @return string
  */
 protected function formatBody($message)
 {
     $header = $message->getHeader('Content-Type');
     if (JsonStringFormatter::isJsonHeader($header)) {
         $formatter = new JsonStringFormatter();
         return $formatter->format($message->getBody());
     } elseif (XmlStringFormatter::isXmlHeader($header)) {
         $formatter = new XmlStringFormatter();
         return $formatter->format($message->getBody());
     }
     $factory = new StringFactoryFormatter();
     return $factory->format($message->getBody());
 }
开发者ID:glooby,项目名称:debug-bundle,代码行数:17,代码来源:AbstractMessageFormatter.php

示例2: visit

 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, array $context)
 {
     $name = urlencode($param->formName);
     $value = urlencode($command[$param->getName()]);
     $content = Stream::factory($param->filter($value));
     if ($request->getBody() === null) {
         $request->setBody(Stream::factory(""));
     }
     $queryChar = '&';
     if ($request->getBody()->__toString() == '') {
         $queryChar = '';
     }
     $request->getBody()->write($queryChar . $name . "=" . $content);
 }
开发者ID:conversely-io,项目名称:conversely-php,代码行数:14,代码来源:PutLocation.php

示例3: getSignature

 /**
  * Calculate signature for request
  *
  * @param RequestInterface $request Request to generate a signature for
  *
  * @return string
  */
 public function getSignature(RequestInterface $request)
 {
     // For POST|PUT set the JSON body string as the params
     if ($request->getMethod() == 'POST' || $request->getMethod() == 'PUT') {
         $params = $request->getBody()->__toString();
         /**
          * If you don't seek() back to the beginning then attempting to
          * send a JSON body > 1MB will probably fail.
          *
          * @link http://stackoverflow.com/q/32359664/99071
          * @link https://groups.google.com/forum/#!topic/guzzle/vkF5druf6AY
          */
         $request->getBody()->seek(0);
         // Make sure to remove any other query params
         $request->setQuery([]);
     } else {
         $params = Query::fromString($request->getQuery(), Query::RFC1738)->toArray();
         $params = $this->prepareParameters($params);
         // Re-Set the query to the properly ordered query string
         $request->setQuery($params);
         $request->getQuery()->setEncodingType(Query::RFC1738);
     }
     $baseString = $this->createBaseString($request, $params);
     return base64_encode($this->sign_HMAC_SHA256($baseString));
 }
开发者ID:ticketevolution,项目名称:ticketevolution-php,代码行数:32,代码来源:TEvoAuth.php

示例4: format

 /**
  * @inheritDoc
  */
 public function format(RequestInterface $request, ResponseInterface $response = null, \Exception $error = null, array $customData = [])
 {
     if (in_array($request->getPath(), $this->paths)) {
         $customData = array_merge(['url' => $this->mask((string) $request->getUrl()), 'resource' => $this->mask($request->getResource()), 'request' => $this->mask((string) $request), 'response' => $this->mask((string) $response), 'res_body' => $response ? $this->mask((string) $response) : 'NULL', 'req_body' => $this->mask((string) $request->getBody())], $customData);
     }
     return parent::format($request, $response, $error, $customData);
 }
开发者ID:onlinetravelgroup,项目名称:ean-client,代码行数:10,代码来源:Formatter.php

示例5: createRingRequest

 /**
  * Creates a Ring request from a request object.
  *
  * This function does not hook up the "then" and "progress" events that
  * would be required for actually sending a Guzzle request through a
  * RingPHP handler.
  *
  * @param RequestInterface $request Request to convert.
  *
  * @return array Converted Guzzle Ring request.
  */
 public static function createRingRequest(RequestInterface $request)
 {
     $options = $request->getConfig()->toArray();
     $url = $request->getUrl();
     // No need to calculate the query string twice (in URL and query).
     $qs = ($pos = strpos($url, '?')) ? substr($url, $pos + 1) : null;
     return ['scheme' => $request->getScheme(), 'http_method' => $request->getMethod(), 'url' => $url, 'uri' => $request->getPath(), 'headers' => $request->getHeaders(), 'body' => $request->getBody(), 'version' => $request->getProtocolVersion(), 'client' => $options, 'query_string' => $qs, 'future' => isset($options['future']) ? $options['future'] : false];
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:19,代码来源:RingBridge.php

示例6: assertRequestHasPostParameter

 protected function assertRequestHasPostParameter($parameterName, $expectedValue, RequestInterface $request)
 {
     /** @var PostBody $requestBody */
     $requestBody = $request->getBody();
     $this->assertNotEmpty($requestBody);
     $this->assertInstanceOf(PostBody::class, $requestBody);
     $actualValue = $requestBody->getField($parameterName);
     $this->assertNotNull($actualValue, "The request should have the post body parameter '{$parameterName}'");
     $this->assertEquals($expectedValue, $actualValue);
 }
开发者ID:fgrosse,项目名称:gitlab-api,代码行数:10,代码来源:GitlabGuzzleClientTest.php

示例7: format

 /**
  * {@inheritdoc}
  * Replaces the ewayCardNumber field in the body with "X"s.
  */
 public function format(RequestInterface $request, ResponseInterface $response = null, \Exception $error = null, array $customData = array())
 {
     $body = $request->getBody()->__toString();
     $newBody = preg_replace_callback('/<ewayCardNumber>(.*?)<\\/ewayCardNumber>/', function ($matches) {
         $privateNumber = str_repeat('X', strlen($matches[1]) - 4) . substr($matches[1], -4);
         return '<ewayCardNumber modified>' . $privateNumber . '</ewayCardNumber>';
     }, $body);
     $newRequest = clone $request;
     $newRequest->setBody(Stream::factory($newBody));
     $request->setBody(Stream::factory($body));
     return parent::format($newRequest, $response, $error, $customData);
 }
开发者ID:bluedogtraining,项目名称:guzzle-eway,代码行数:16,代码来源:Formatter.php

示例8: visit

 public function visit(GuzzleCommandInterface $command, RequestInterface $request, Parameter $param, array $context)
 {
     $body = $request->getBody();
     if (!$body instanceof PostBodyInterface) {
         throw new \RuntimeException('Must be a POST body interface');
     }
     $value = $param->filter($command[$param->getName()]);
     if (!$value instanceof PostFileInterface) {
         $value = new PostFile($param->getWireName(), $value);
     }
     $body->addFile($value);
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:12,代码来源:PostFileLocation.php

示例9: iSendARequestWithFormData

 /**
  * Sends HTTP request to specific URL with form data from PyString.
  *
  * @param string       $method request method
  * @param string       $url    relative url
  * @param PyStringNode $body   request body
  *
  * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)" with form data:$/
  */
 public function iSendARequestWithFormData($method, $url, PyStringNode $body)
 {
     $url = $this->prepareUrl($url);
     $body = $this->replacePlaceHolder(trim($body));
     $fields = array();
     parse_str(implode('&', explode("\n", $body)), $fields);
     $this->request = $this->getClient()->createRequest($method, $url);
     /** @var \GuzzleHttp\Post\PostBodyInterface $requestBody */
     $requestBody = $this->request->getBody();
     foreach ($fields as $key => $value) {
         $requestBody->setField($key, $value);
     }
     $this->sendRequest();
 }
开发者ID:pavelsmolka,项目名称:WebApiExtension,代码行数:23,代码来源:WebApiContext.php

示例10: after

 public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         $body = $request->getBody();
         if (!$body instanceof PostBodyInterface) {
             throw new \RuntimeException('Must be a POST body interface');
         }
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $body->setField($key, $this->prepareValue($value, $additional));
             }
         }
     }
 }
开发者ID:ryanwinchester-forks,项目名称:guzzle-services,代码行数:15,代码来源:PostFieldLocation.php

示例11: signRequest

 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     /** @var PostBodyInterface $body */
     $body = $request->getBody();
     $body->setField('Timestamp', gmdate('c'));
     $body->setField('SignatureVersion', '2');
     $body->setField('SignatureMethod', 'HmacSHA256');
     $body->setField('AWSAccessKeyId', $credentials->getAccessKeyId());
     if ($token = $credentials->getSecurityToken()) {
         $body->setField('SecurityToken', $token);
     }
     // build string to sign
     $sign = $request->getMethod() . "\n" . $request->getHost() . "\n" . '/' . "\n" . $this->getCanonicalizedParameterString($body);
     $request->getConfig()->set('aws.signature', $sign);
     $body->setField('Signature', base64_encode(hash_hmac('sha256', $sign, $credentials->getSecretKey(), true)));
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:16,代码来源:SignatureV2.php

示例12: getSignature

 /**
  * Calculate signature for request
  *
  * @param RequestInterface $request Request to generate a signature for
  *
  * @return string
  *
  * @throws \RuntimeException
  */
 public function getSignature(RequestInterface $request)
 {
     // For POST|PUT set the JSON body string as the params
     if ($request->getMethod() == 'POST' || $request->getMethod() == 'PUT') {
         $params = $request->getBody()->__toString();
         // Make sure to remove any other query params
         $request->setQuery([]);
     } else {
         $params = Query::fromString($request->getQuery(), Query::RFC1738)->toArray();
         $params = $this->prepareParameters($params);
         // Re-Set the query to the properly ordered query string
         $request->setQuery($params);
         $request->getQuery()->setEncodingType(Query::RFC1738);
     }
     $baseString = $this->createBaseString($request, $params);
     return base64_encode($this->sign_HMAC_SHA256($baseString));
 }
开发者ID:sonnygauran,项目名称:ticketevolution-php,代码行数:26,代码来源:TEvoAuth.php

示例13: getSignature

 /**
  * Calculate signature for request
  *
  * This method mostly copy pasted from original class, except its bottom part where we actually hashing our request
  *
  * @param RequestInterface $request Request to generate a signature for
  * @param array $params Oauth parameters.
  *
  * @return string
  */
 public function getSignature(RequestInterface $request, array $params)
 {
     // Remove oauth_signature if present
     // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
     unset($params['oauth_signature']);
     // Add POST fields if the request uses POST fields and no files
     $body = $request->getBody();
     if ($body instanceof PostBodyInterface && !$body->getFiles()) {
         $query = Query::fromString($body->getFields(true));
         $params += $query->toArray();
     }
     // Parse & add query string parameters as base string parameters
     $query = Query::fromString((string) $request->getQuery());
     $query->setEncodingType(Query::RFC1738);
     $params += $query->toArray();
     $baseString = $this->createBaseString($request, $this->prepareParameters($params));
     // changed code
     return base64_encode(hash_hmac('sha1', $baseString, $this->consumer_secret, true));
 }
开发者ID:mac2000,项目名称:woo-commerce-api-client,代码行数:29,代码来源:WooAuth1.php

示例14: getZboziApiRequest

 /**
  * @param \GuzzleHttp\Message\RequestInterface $request
  * @return \SlevomatZboziApi\Request\ZboziApiRequest
  */
 private function getZboziApiRequest(\GuzzleHttp\Message\RequestInterface $request)
 {
     return new ZboziApiRequest($request->getMethod(), $request->getUrl(), $request->getHeaders(), $request->getBody() === null ? null : json_decode((string) $request->getBody()));
 }
开发者ID:pepakriz,项目名称:zbozi-api-php-library,代码行数:8,代码来源:RequestMaker.php

示例15: modifyRedirectRequest

 private function modifyRedirectRequest(RequestInterface $request, ResponseInterface $response)
 {
     $config = $request->getConfig();
     // Use a GET request if this is an entity enclosing request and we are
     // not forcing RFC compliance, but rather emulating what all browsers
     // would do.
     $statusCode = $response->getStatusCode();
     if ($statusCode == 303 || $statusCode <= 302 && $request->getBody() && !$config->getPath('redirect/strict')) {
         $request->setMethod('GET');
         $request->setBody(null);
     }
     $previousUrl = $request->getUrl();
     $this->setRedirectUrl($request, $response);
     $this->rewindEntityBody($request);
     // Add the Referer header if it is told to do so and only
     // add the header if we are not redirecting from https to http.
     if ($config->getPath('redirect/referer') && ($request->getScheme() == 'https' || $request->getScheme() == $config['redirect_scheme'])) {
         $url = Url::fromString($previousUrl);
         $url->setUsername(null);
         $url->setPassword(null);
         $request->setHeader('Referer', (string) $url);
     } else {
         $request->removeHeader('Referer');
     }
 }
开发者ID:bangordailynews,项目名称:bdnindex,代码行数:25,代码来源:Redirect.php


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