2011-01-07 43 views
2

製作像一個簡單的要求:獲取Zend_Http最終網址

$client = new Zend_Http_Client('http://example.org'); 
$response = $client->request(); 

我怎樣才能獲得重定向後的最終網址是什麼? 我沒有看到文檔或API文檔中的一種方式,除非我錯過了一些東西。

在此先感謝。

回答

0

未測試:

$response->getHeader('Location'); 
+0

當存在重定向時位置包含在標題中。標題不包含最終的網址。我已經放棄並開始使用捲曲。謝謝你嘗試! – clips404 2011-01-11 16:30:58

0

獲得來自客戶端的最後一個請求,然後提取頭。如果有重定向

$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 
2

一個Zend_Http_Client更新的最後一個URL到Zend_Http_Client-> uri屬性。

$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/"