php curl 不返回头部,php-curl不返回内容长度标头

尝试使用curl获取图像文件大小,但未返回内容长度标头:

$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请求…

如果您将-I与您的命令行版本一起使用,它们将更加相似.

标签:php,curl

来源: https://codeday.me/bug/20191011/1896005.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值