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


PHP RequestInterface::setBody方法代码示例

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


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

示例1: after

 public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     foreach ($this->buffered as $param) {
         $this->visitWithValue($command[$param->getName()], $param, $command);
     }
     $this->buffered = array();
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $additional->setName($key);
                 $this->visitWithValue($value, $additional, $command);
             }
         }
         $additional->setName(null);
     }
     // If data was found that needs to be serialized, then do so
     $xml = null;
     if ($this->writer) {
         $xml = $this->finishDocument($this->writer);
     } elseif ($operation->getData('xmlAllowEmpty')) {
         // Check if XML should always be sent for the command
         $writer = $this->createRootElement($operation);
         $xml = $this->finishDocument($writer);
     }
     if ($xml) {
         $request->setBody(Stream::factory($xml));
         // Don't overwrite the Content-Type if one is set
         if ($this->contentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
     $this->writer = null;
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:34,代码来源:XmlLocation.php

示例2: 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

示例3: 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

示例4: after

 public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $data = $this->jsonData;
     $this->jsonData = null;
     // Add additional parameters to the JSON document
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $data[$key] = $this->prepareValue($value, $additional);
             }
         }
     }
     // Don't overwrite the Content-Type if one is set
     if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
         $request->setHeader('Content-Type', $this->jsonContentType);
     }
     $request->setBody(Stream::factory(json_encode($data)));
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:19,代码来源:JsonLocation.php

示例5: payload

 protected function payload(RequestInterface $request, StructureShape $member, array $value)
 {
     $request->setHeader('Content-Type', $this->contentType);
     $request->setBody(Stream::factory($this->jsonFormatter->build($member, $value)));
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:5,代码来源:RestJsonSerializer.php

示例6: 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

示例7: addRequestContent

 /**
  * @param InputInterface   $input
  * @param RequestInterface $request
  *
  * @return Stream
  * @throws Exception
  */
 protected function addRequestContent(InputInterface $input, RequestInterface $request)
 {
     $type = $input->getOption('request_type');
     if (!is_string($type)) {
         throw new Exception('request_type (-t) is a required parameter when request_content (-c) is used');
     }
     $body = Stream::factory($input->getOption('request_content'));
     $request->setBody($body);
     $request->setHeader('Content-Type', $this->parseContentType($type));
 }
开发者ID:ShaneArmstrong,项目名称:magento-rest-test,代码行数:17,代码来源:RequestCommand.php

示例8: visit

 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, array $context)
 {
     $value = $command[$param->getName()];
     $request->setBody(Stream::factory($param->filter($value)));
 }
开发者ID:ryanwinchester-forks,项目名称:guzzle-services,代码行数:5,代码来源:BodyLocation.php

示例9: add_json

 private function add_json(RequestInterface $request, $value)
 {
     if (!$request->hasHeader('Content-Type')) {
         $request->setHeader('Content-Type', 'application/json');
     }
     $request->setBody(Stream::factory(json_encode($value)));
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:7,代码来源:MessageFactory.php

示例10: payload

 /**
  * @param RequestInterface $request
  * @param string           $name
  * @param mixed            $args
  *
  * @return \GuzzleHttp\Stream\StreamInterface|void
  */
 protected function payload(RequestInterface $request, $name, $args)
 {
     $request->setHeader('Content-Type', 'application/xml');
     $request->setBody(Stream::factory($this->serializer->serialize($args)));
 }
开发者ID:danielcosta,项目名称:sellercenter-sdk,代码行数:12,代码来源:RestXmlSerializer.php

示例11: addPostData

 /**
  * Apply POST fields and files to a request to attempt to give an accurate
  * representation.
  *
  * @param RequestInterface $request Request to update
  * @param array            $body    Body to apply
  */
 protected function addPostData(RequestInterface $request, array $body)
 {
     static $fields = ['string' => true, 'array' => true, 'NULL' => true, 'boolean' => true, 'double' => true, 'integer' => true];
     $post = new PostBody();
     foreach ($body as $key => $value) {
         if (isset($fields[gettype($value)])) {
             $post->setField($key, $value);
         } elseif ($value instanceof PostFileInterface) {
             $post->addFile($value);
         } else {
             $post->addFile(new PostFile($key, $value));
         }
     }
     if ($request->getHeader('Content-Type') == 'multipart/form-data') {
         $post->forceMultipartUpload(true);
     }
     $request->setBody($post);
 }
开发者ID:DeveloperOwl,项目名称:flipside.io,代码行数:25,代码来源:MessageFactory.php

示例12: applyPayload

 private function applyPayload(RequestInterface $request, StructureShape $input, $name, array $args)
 {
     if (!isset($args[$name])) {
         return;
     }
     $m = $input->getMember($name);
     if ($m['streaming'] || ($m['type'] == 'string' || $m['type'] == 'blob')) {
         // Streaming bodies or payloads that are strings are
         // always just a stream of data.
         $request->setBody(Stream::factory($args[$name]));
     } else {
         $this->payload($request, $m, $args[$name]);
     }
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:14,代码来源:RestSerializer.php

示例13: payload

 protected function payload(RequestInterface $request, StructureShape $member, array $value)
 {
     $request->setHeader('Content-Type', 'application/xml');
     $request->setBody(Stream::factory($this->xmlBody->build($member, $value)));
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:5,代码来源:RestXmlSerializer.php

示例14: addPostData

 /**
  * Apply POST fields and files to a request to attempt to give an accurate
  * representation.
  *
  * @param RequestInterface $request Request to update
  * @param array            $body    Body to apply
  */
 protected function addPostData(RequestInterface $request, array $body)
 {
     static $fields = ['string' => true, 'array' => true, 'NULL' => true, 'boolean' => true, 'double' => true, 'integer' => true];
     $post = new PostBody();
     foreach ($body as $key => $value) {
         if (isset($fields[gettype($value)])) {
             $post->setField($key, $value);
         } elseif ($value instanceof PostFileInterface) {
             $post->addFile($value);
         } else {
             $post->addFile(new PostFile($key, $value));
         }
     }
     $request->setBody($post);
     $post->applyRequestHeaders($request);
 }
开发者ID:Cywaithaka,项目名称:S.A.F.E.-Open-Source-Microfinance-Suite,代码行数:23,代码来源:MessageFactory.php

示例15: withBody

 public function withBody(StreamInterface $stream)
 {
     $this->expectedRequest->setBody($stream);
     return $this;
 }
开发者ID:lezhnev74,项目名称:GuzzleHttpMock,代码行数:5,代码来源:RequestExpectation.php


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