本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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)));
}
示例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)));
}
示例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');
}
}
示例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));
}
示例8: visit
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, array $context)
{
$value = $command[$param->getName()];
$request->setBody(Stream::factory($param->filter($value)));
}
示例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)));
}
示例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)));
}
示例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);
}
示例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]);
}
}
示例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)));
}
示例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);
}
示例15: withBody
public function withBody(StreamInterface $stream)
{
$this->expectedRequest->setBody($stream);
return $this;
}