Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php zend http客户端当前url_Php_Zend Framework_Redirect_Curl - Fatal编程技术网

Php zend http客户端当前url

Php zend http客户端当前url,php,zend-framework,redirect,curl,Php,Zend Framework,Redirect,Curl,我正在将一个用普通php编写的旧项目移植到zend framework(我是zend的新手),我正在zend项目中使用zend http客户端(带有cURL适配器)来替换旧php项目的cULR部分。我被卡住了,因为我不知道zend http客户端的备用 $landing_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 在cURL请求期间的任何重定向之后返回登录页的url。我可以用zend成功地完成以下工作 $config = array(

我正在将一个用普通php编写的旧项目移植到zend framework(我是zend的新手),我正在zend项目中使用zend http客户端(带有cURL适配器)来替换旧php项目的cULR部分。我被卡住了,因为我不知道zend http客户端的备用

$landing_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
在cURL请求期间的任何重定向之后返回登录页的url。我可以用zend成功地完成以下工作

$config = array(
            'adapter'   => 'Zend_Http_Client_Adapter_Curl',
            'curloptions' => array(
                    CURLOPT_RETURNTRANSFER    =>    true,
                    CURLOPT_FOLLOWLOCATION    =>    true,
            ),
    );
    $redirecting_page_address ='https://www.domain.tld/someredirectingurl';

    $client = new Zend_Http_Client($redirecting_page_address, $config);

    $response = $client->request();

使用
$response->getBody()
获得所需页面作为输出现在我想知道
$redirecting\u page\u address
重定向到的登录页面的url。提前感谢。

如果重定向是通过标题完成的,您可以使用

if ($response->isRedirect()){
     $newUrl = $response->getHeader('Location');
}

在我对此的研究中,我发现在当前版本的zend framework(2.0.6)之前没有办法做到这一点,也许在未来的版本中可以包括此功能。

正如Cyril自己回答的那样,zend framework 2(2.2.8 2014-09-17)中没有高级API来获取有效的URL。但是,您可以获取原始的curl句柄并在其上使用本机PHP函数:

// $client would be a Zend_Http_Client
$handle = $client->getAdapter()->getHandle();
$effectiveUrl = curl_getinfo($handle, CURLINFO_EFFECTIVE_URL);

这对我没有帮助,因为在重定向完成后,在重定向位置标头不可用后,我需要url。谢谢你的回复。