當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。