當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RequestInterface::setBody方法代碼示例

本文整理匯總了PHP中Guzzle\Http\Message\RequestInterface::setBody方法的典型用法代碼示例。如果您正苦於以下問題:PHP RequestInterface::setBody方法的具體用法?PHP RequestInterface::setBody怎麽用?PHP RequestInterface::setBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Guzzle\Http\Message\RequestInterface的用法示例。


在下文中一共展示了RequestInterface::setBody方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setBody

 public static function setBody(RequestInterface $request, $body, $options)
 {
     $type = isset($options['request_type']) ? $options['request_type'] : 'json';
     $header = null;
     // Encoding request body into JSON format
     if ($type == 'json') {
         $body = count($body) === 0 ? '{}' : json_encode($body, empty($body) ? JSON_FORCE_OBJECT : 0);
         return $request->setBody($body, 'application/json');
     }
     if ($type == 'raw') {
         // Raw body
         return $request->setBody($body, $header);
     }
 }
開發者ID:JamesAusten,項目名稱:helpful-php,代碼行數:14,代碼來源:RequestHandler.php

示例2: after

public function after(CommandInterface $command, RequestInterface $request)
{
$xml = null;


 if (isset($this->data[$command])) {
$xml = $this->finishDocument($this->data[$command]);
unset($this->data[$command]);
} else {

 $operation = $command->getOperation();
if ($operation->getData('xmlAllowEmpty')) {
$xmlWriter = $this->createRootElement($operation);
$xml = $this->finishDocument($xmlWriter);
}
}

if ($xml) {

 if ($this->contentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->contentType);
}
$request->setBody($xml);
}
}
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:25,代碼來源:XmlVisitor.php

示例3: setBody

 /**
  * @param RequestInterface $request
  * @param \Guzzle\Http\EntityBodyInterface|string $body
  * @param array $options
  * @return mixed
  */
 public static function setBody(RequestInterface $request, $body, $options)
 {
     $type = isset($options['request_type']) ? $options['request_type'] : 'raw';
     $header = null;
     if ($type == 'raw') {
         // Raw body
         return $request->setBody($body, $header);
     }
 }
開發者ID:dev-zoikmail,項目名稱:zoikmail,代碼行數:15,代碼來源:RequestHandler.php

示例4: visit

 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
 {
     $entityBody = EntityBody::factory($value);
     $request->setBody($entityBody);
     $this->addExpectHeader($request, $entityBody, $param->getData('expect_header'));
     // Add the Content-Encoding header if one is set on the EntityBody
     if ($encoding = $entityBody->getContentEncoding()) {
         $request->setHeader('Content-Encoding', $encoding);
     }
 }
開發者ID:xkeygmbh,項目名稱:ifresco-php,代碼行數:13,代碼來源:BodyVisitor.php

示例5: after

 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->jsonContentType);
         }
         $request->setBody(json_encode($this->data[$command]));
         unset($this->data[$command]);
     }
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:10,代碼來源:JsonVisitor.php

示例6: after

 /**
  * {@inheritdoc}
  */
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         $json = $this->data[$command];
         unset($this->data[$command]);
         $request->setBody(json_encode($json))->removeHeader('Expect');
         if ($this->jsonContentType) {
             $request->setHeader('Content-Type', $this->jsonContentType);
         }
     }
 }
開發者ID:jsnshrmn,項目名稱:Suma,代碼行數:14,代碼來源:JsonBodyVisitor.php

示例7: after

 /**
  * {@inheritdoc}
  */
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         $request->setBody($this->data[$command]->asXML());
         unset($this->data[$command]);
         // Don't overwrite the Content-Type if one is set
         if ($this->contentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
 }
開發者ID:noahkim,項目名稱:kowop,代碼行數:14,代碼來源:XmlVisitor.php

示例8: after

 /**
  * {@inheritdoc}
  */
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         $xml = $this->data[$command];
         unset($this->data[$command]);
         $request->setBody($xml->asXML());
         if ($this->contentType) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
 }
開發者ID:xkeygmbh,項目名稱:ifresco-php,代碼行數:14,代碼來源:XmlVisitor.php

示例9: after

 /**
  * {@inheritdoc}
  */
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         $json = $this->data[$command];
         unset($this->data[$command]);
         $request->setBody(json_encode($json));
         // Don't overwrite the Content-Type if one is set
         if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->jsonContentType);
         }
     }
 }
開發者ID:KANU82,項目名稱:guzzle,代碼行數:15,代碼來源:JsonVisitor.php

示例10: setBody

 public static function setBody(RequestInterface $request, $body, $options)
 {
     $type = isset($options['request_type']) ? $options['request_type'] : 'form';
     $header = null;
     if ($type == 'form') {
         // Encoding body into form-urlencoded format
         return $request->addPostFields($body);
     }
     if ($type == 'raw') {
         // Raw body
         return $request->setBody($body, $header);
     }
 }
開發者ID:apetrova0912,項目名稱:buffer-php,代碼行數:13,代碼來源:RequestHandler.php

示例11: after

 public function after(CommandInterface $command, RequestInterface $request)
 {
     $xml = null;
     // If data was found that needs to be serialized, then do so
     if (isset($this->data[$command])) {
         $xml = $this->data[$command]->asXML();
         unset($this->data[$command]);
     } else {
         // Check if XML should always be sent for the command
         $operation = $command->getOperation();
         if ($operation->getData('xmlAllowEmpty')) {
             $xml = $this->createRootElement($operation)->asXML();
         }
     }
     if ($xml) {
         $request->setBody($xml);
         // Don't overwrite the Content-Type if one is set
         if ($this->contentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
 }
開發者ID:creazy412,項目名稱:vmware-win10-c65-drupal7,代碼行數:22,代碼來源:XmlVisitor.php

示例12: visit_body

protected function visit_body(RequestInterface $request, $value, $flags)
{
if ($request instanceof EntityEnclosingRequestInterface) {
$request->setBody($value);
} else {
throw new InvalidArgumentException('Attempting to set a body on a non-entity-enclosing request');
}
}
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:8,代碼來源:RequestFactory.php

示例13: visit

 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, RequestInterface $request, $key, $value)
 {
     $request->setBody(EntityBody::factory($value));
 }
開發者ID:jsnshrmn,項目名稱:Suma,代碼行數:7,代碼來源:BodyVisitor.php


注:本文中的Guzzle\Http\Message\RequestInterface::setBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。