首頁 > php教程 > php手册 > curl下载文件得到header和body

curl下载文件得到header和body

WBOY
發布: 2016-06-06 20:11:22
原創
1410 人瀏覽過

function curl_get_file_contents($URL) $user_agent = Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; 4399Box.560; .NET4.0C; .NET4.0E); $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HEA

function curl_get_file_contents($URL){
    $user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; 4399Box.560; .NET4.0C; .NET4.0E)";
    $c = curl_init();
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_HEADER, 1);
    curl_setopt($c, CURLOPT_USERAGENT, $user_agent);
    curl_setopt($c, CURLOPT_URL, $URL);
    $response = curl_exec($c);
  $header_size = curl_getinfo($c, CURLINFO_HEADER_SIZE);
  $header = substr($response, 0, $header_size);
  $body = substr($response, $header_size);
    curl_close($c);
    if ($body) {
      return array($header, $body);}
    else {return FALSE;}
}



附带昆爷建议直接得到header内容:

$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_USERAGENT, $user_agent);
curl_setopt($c, CURLOPT_URL, $url);
$response = curl_exec($c);
$header = curl_getinfo($c);


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板