获取标头作为 CURL 的一部分


Get Headers as part of CURL

我已经编写了一些代码来通过curl获取文件。我只想要标题而不是实际文件本身

$info = curl_init() or die('error 1');
    curl_setopt($info, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($info, CURLOPT_PORT , 8089);
    curl_setopt($info, CURLOPT_URL, $url);
    curl_setopt($info, CURLOPT_HEADER,true); 
    curl_setopt($info, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($info, CURLOPT_NOBODY, true);
        //curl_setopt($info, CURLOPT_SSL_VERIFYPEER, 0);
        curl_exec($info);
        if(!curl_errno($info)){
            $response = curl_getinfo($info);
            echo "<pre>";
            print_r(get_headers($response));
            echo "</pre>";
        }else{
            echo "error!";
            echo "<br>" . curl_error($info);
        }

但是,由此返回的响应不包含任何应该在标头中的信息 - 例如文件名

array(26) {
  ["url"]=>
  string(55) "https://www.filepicker.io/api/file/CjDfxG0WSmGiY3O2eKDE"
  ["content_type"]=>
  string(9) "image/png"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(840)
  ["request_size"]=>
  int(86)

["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(1.578048)
  ["namelookup_time"]=>
  float(0.000494)
  ["connect_time"]=>
  float(0.026931)
  ["pretransfer_time"]=>
  float(0.13615)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(0)
  ["speed_download"]=>
  float(0)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(965985)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(1.578002)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(11) "79.125.4.68"
  ["primary_port"]=>
  int(443)
  ["local_ip"]=>
  string(11) "192.168.0.9"
  ["local_port"]=>
  int(53950)
  ["redirect_url"]=>
  string(0) ""
}

那么如何获取实际的标头本身呢?

发生这种情况的原因是因为我丢弃了curl_exec的输入。我将代码的该部分更改为:

$headers=curl_exec($info);