开发者

Getting Zend_Http Final URL

Making a simple request like:

$client = new Zend_Http_Client('http:/开发者_运维知识库/example.org');
$response = $client->request();

How can I get the final URL after the redirects? I have not seen a way in the documentation or the API docs unless I'm missing something.

Thanks in advance.


Zend_Http_Client update the last URL into Zend_Http_Client->uri property if there is redirect.

$sourceUrl = 'http://google.com';
$client = new Zend_Http_Client($sourceUrl); 
$response = $client->request(); 
$finalUrl = $client->getUri()->__toString();

var_dump($sourceUrl);
// string(17) "http://google.com"
var_dump($finalUrl);
// string(25) "http://www.google.com:80/" 


Not tested :

$response->getHeader('Location');


Get the last request from the client and then extract the headers.

$client = new Zend_Http_Client('http://webonyx.com');
$response = $client->request();
$lastHeaders = Zend_Http_Response::extractHeaders($client->getLastRequest());

// $lastHeaders['host'] will be your final redirected host
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜