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


PHP Client::prepareBody方法代码示例

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


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

示例1: _prepareBody

 /**
  * Prepare the request body (for POST and PUT requests)
  *
  * @return string
  * @throws \Zend\Http\Client\Exception\RuntimeException
  */
 protected function _prepareBody()
 {
     if ($this->_streamingRequest) {
         $this->setHeaders(array('Content-Length' => $this->raw_post_data->getTotalSize()));
         return $this->raw_post_data;
     } else {
         return parent::prepareBody();
     }
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:15,代码来源:Client.php

示例2: _prepareBody

 /**
  * Prepare the request body (for POST and PUT requests)
  *
  * @return string
  * @throws \Zend\Http\Client\Exception\ExceptionInterface
  */
 protected function _prepareBody()
 {
     if ($this->_streamingRequest) {
         $this->setHeaders(self::CONTENT_LENGTH, $this->raw_post_data->getTotalSize());
         return $this->raw_post_data;
     } else {
         return parent::prepareBody();
     }
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:15,代码来源:HttpClient.php

示例3: prepareBody

 /**
  * Prepare the request body (for PATCH, POST and PUT requests)
  *
  * @return string
  * @throws \Zend\Http\Client\Exception\RuntimeException
  */
 protected function prepareBody()
 {
     if (!count($this->getRequest()->getFiles())) {
         return parent::prepareBody();
     }
     // According to RFC2616, a TRACE request should not have a body.
     if ($this->getRequest()->isTrace()) {
         return '';
     }
     $rawBody = $this->getRequest()->getContent();
     if (!empty($rawBody)) {
         return $rawBody;
     }
     $body = '';
     $totalFiles = count($this->getRequest()->getFiles()->toArray());
     if (!$this->getRequest()->getHeaders()->has('Content-Type')) {
         // If we have files to upload, force encType to multipart/form-data
         if ($totalFiles > 0) {
             $this->setEncType(self::ENC_FORMDATA);
         }
     } else {
         $this->setEncType($this->getHeader('Content-Type'));
     }
     // If we have POST parameters encode and add them to the body
     // Do not add the files at that moment
     if (count($this->getRequest()->getPost()->toArray()) > 0 || $totalFiles > 0) {
         if (stripos($this->getEncType(), self::ENC_FORMDATA) === 0) {
             $boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
             $this->boundary = $boundary;
             $this->setEncType(self::ENC_FORMDATA, $boundary);
             // Get POST parameters and encode them
             $params = self::flattenParametersArray($this->getRequest()->getPost()->toArray());
             foreach ($params as $pp) {
                 $body .= $this->encodeFormData($boundary, $pp[0], $pp[1]);
             }
             // Notice: The files will be added later
         } elseif (stripos($this->getEncType(), self::ENC_URLENCODED) === 0) {
             // Encode body as application/x-www-form-urlencoded
             $body = http_build_query($this->getRequest()->getPost()->toArray());
         } else {
             throw new ZendClient\Exception\RuntimeException("Cannot handle content type '{$this->encType}' automatically");
         }
     }
     return $body;
 }
开发者ID:Karl-Dawson,项目名称:ZendServerWebApiModule,代码行数:51,代码来源:Client.php


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