本文整理汇总了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();
}