php curl 返回文件头,从php curl发送请求头文件信息

如果您设置卷曲选项CURLOPT_FOLLOWLOCATION,cURL将跟随您的位置重定向.

如果要获取标题,请将选项CURLOPT_HEADER设置为1,并从curl_exec()返回的HTTP响应将包含标题.你可以解析他们的位置.

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_HEADER, 1); // return HTTP headers with response

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return the response rather than output it

$resp = curl_exec($ch);

list($headers, $response) = explode("\r\n\r\n", $resp, 2);

// $headers now has a string of the HTTP headers

// $response is the body of the HTTP response

$headers = explode("\n", $headers);

foreach($headers as $header) {

if (stripos($header, 'Location:') !== false) {

echo "The location header is: '$header'";

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值