curl 探测java网站_使用cURL查找网站重定向的位置?

我正在尝试获取服务器重定向网址 . 我试过了

function http_head_curl($url,$timeout=10)

{

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // in seconds

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_NOBODY, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$res = curl_exec($ch);

if ($res === false) {

throw new RuntimeException("cURL exception: ".curl_errno($ch).": ".curl_error($ch));

}

return trim($res);

}

echo http_head_curl("http://www.site.com",$timeout=10);

结果是;

HTTP / 1.1 301永久移动日期:太阳,2013年5月12日23:34:22 GMT服务器:LiteSpeed连接:关闭X-Powered-By:PHP / 5.3.23 Set-Cookie:PHPSESSID = 0d4b28dd02bd3d8413c92f71253e8b31;路径= /; HttpOnly X-Pingback:http://site.com/xmlrpc.php Content-Type:text / html; charset = UTF-8位置:http://site.com/ HTTP / 1.1 200 OK日期:太阳,2013年5月12日23:34:23 GMT服务器:LiteSpeed连接:关闭X-Powered-By:PHP / 5.3.23 Set-Cookie:PHPSESSID = 630ed27f107c07d25ee6dbfcb02e8dec;路径= /; HttpOnly X-Pingback:http://site.com/xmlrpc.php Content-Type:text / html;字符集= UTF-8

它显示几乎所有 Headers 信息,但不显示重定向的位置 . 如何获取重定向的页面网址?

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值