我正在构建一个网站爬网程序,并使用带有这些选项的cURL class获取标头,以便在将完整的网站下载为text / html且低于指定大小限制之前,可以提取其mime / type和content-length.
这些是我的卷发选项
$c->setopt(CURLOPT_URL, $theURL);
$c->setopt(CURLOPT_HEADER, false);
$c->setopt(CURLOPT_RETURNTRANSFER, true);
$c->setopt(CURLOPT_TIMEOUT, 10);
$c->setopt(CURLOPT_CONNECTTIMEOUT, 10);
$c->setopt(CURLOPT_NOBODY, TRUE);
$c->setopt(CURLOPT_FOLLOWLOCATION, TRUE);
$c->setopt(CURLOPT_MAXREDIRS, 2);
// Within Class
$theReturnValue = curl_exec($this->m_handle);
$this->m_status = curl_getinfo($this->m_handle) ;
但它总是返回[download_content_length] =>即使没有CURLOPT_NOBODY,也为-1,但是检索的数据(整个文件)是正确的.
解决方法:
“this returns -1 if the size isn’t known”
标签:curl,php
来源: https://codeday.me/bug/20191102/1993933.html