卷曲没有返回内容长度标题

问题描述:

试图让图像文件大小不返回:卷曲没有返回内容长度标题

$url ="http://www.collegefashion.net/wp-content/plugins/feed-comments-number/image.php?1263"; 
$fp = curl_init(); 
curl_setopt($fp, CURLOPT_NOBODY, true); 
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($fp, CURLOPT_FAILONERROR,1); 
curl_setopt($fp, CURLOPT_REFERER,''); 
curl_setopt($fp, CURLOPT_URL, $url); 
curl_setopt($fp, CURLOPT_HEADER,1); 
curl_setopt($fp, CURLOPT_USERAGENT,'Mozilla/5.0'); 
$body = curl_exec($fp); 

的var_dump($体):

HTTP/1.1 200 OK 
Date: Sun, 02 May 2010 02:50:20 GMT 
Server: Apache/2.0.63 (CentOS) 
X-Powered-By: W3 Total Cache/0.8.5.2 
X-Pingback: http://www.collegefashion.net/xmlrpc.php 
Cache-Control: no-cache, must-revalidate 
Expires: Sat, 26 Jul 1997 05:00:00 GMT 
Content-Type: image/png 

它通过ssh工作虽然:

curl -i http://www.collegefashion.net/wp-content/plugins/feed-comments-number/image.php?1263 
HTTP/1.1 200 OK 
Date: Sun, 02 May 2010 03:38:43 GMT 
Server: Apache/2.0.63 (CentOS) 
X-Powered-By: W3 Total Cache/0.8.5.2 
X-Pingback: http://www.collegefashion.net/xmlrpc.php 
Cache-Control: no-cache, must-revalidate 
Expires: Sat, 26 Jul 1997 05:00:00 GMT 
Content-Length: 347 
Content-Type: image/png 

CURLOPT_NOBODY使HEAD请求,同时用-i命令行是一个GET请求......

如果你 - 我用你的命令行版本,他们将有更多的类似。

+0

谢谢!就是这样。头部请求不会返回该服务器的内容长度。 – 2010-05-03 06:36:36

+0

只需添加:一些服务器只是拒绝HEAD请求并返回状态码405(即“不允许使用的方法”) – 2013-01-28 10:20:22

检查curl_getinfo()

$size = curl_getinfo($fp, CURLINFO_CONTENT_LENGTH_DOWNLOAD); 

curl_exec()之后执行。其他

一种选择是设置 CURLOPT_HEADERfalse,只是做 strlen($body) - 忽略这一点,我没有你正在使用CURLOPT_NOBODY注意到。