/** * 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(); } }
/** * 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(); } }
/** * 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; }