本文整理匯總了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();
}
}
示例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();
}
}
示例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;
}