1

if i use curl via php to get just header of a url. it's cost to get all content of response bandwidth for my request? or just as lenght of header i get. my code is something like these:

<?php

$url='http://www.yahoo.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, true);
$buffer = curl_exec($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
$header_size = $curl_info[header_size];
$header = substr($buffer, 0, $header_size);

echo $header;
4

1 回答 1

3

使用CURLOPT_NOBODY使 curl 发送HEAD请求,因此您只得到响应的标头,没有内容。

于 2013-01-12T15:35:57.170 回答