本文整理匯總了PHP中Guzzle\Http\EntityBody::getContentLength方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityBody::getContentLength方法的具體用法?PHP EntityBody::getContentLength怎麽用?PHP EntityBody::getContentLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Guzzle\Http\EntityBody
的用法示例。
在下文中一共展示了EntityBody::getContentLength方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setBody
/**
* Set the body of the request
*
* @param string|resource|EntityBody $body Body to use in the entity body
* of the request
* @param string $contentType (optional) Content-Type to set. Leave null
* to use an existing Content-Type or to guess the Content-Type
* @param bool $tryChunkedTransfer (optional) Set to TRUE to try to use
* Tranfer-Encoding chunked
*
* @return EntityEnclosingRequest
* @throws RequestException if the protocol is < 1.1 and Content-Length can
* not be determined
*/
public function setBody($body, $contentType = null, $tryChunkedTransfer = false)
{
$this->body = EntityBody::factory($body);
$this->removeHeader('Content-Length');
$this->setHeader('Expect', '100-Continue');
if ($contentType) {
$this->setHeader('Content-Type', (string) $contentType);
}
if ($tryChunkedTransfer) {
$this->setHeader('Transfer-Encoding', 'chunked');
} else {
$this->removeHeader('Transfer-Encoding');
// Set the Content-Length header if it can be determined
$size = $this->body->getContentLength();
if ($size !== null && $size !== false) {
$this->setHeader('Content-Length', $size);
} else {
if ('1.1' == $this->protocolVersion) {
$this->setHeader('Transfer-Encoding', 'chunked');
} else {
throw new RequestException('Cannot determine entity body ' . 'size and cannot use chunked Transfer-Encoding when ' . 'using HTTP/' . $this->protocolVersion);
}
}
}
return $this;
}
示例2: getContentLength
/**
* @return int
*/
public function getContentLength()
{
return $this->contentLength !== null ? $this->contentLength : $this->content->getContentLength();
}
示例3: getContentLength
/**
* @return int
*/
public function getContentLength()
{
return $this->contentLength ?: $this->content->getContentLength();
}