phpzend-http-client

How to retrieve full Zend_Http_Client GET URI?


I have something like that:

    $client = new Zend_Http_Client('http://www.site.com');
    $client->setParameterGet(array(
        'platform'     => $platform,
        'clientId'     => $clientId,
        'deploymentId' => $deploymentId,
    ));

    try {
        $response = $client->request();
        ...

This would generate a request similar to 'http://www.site.com/?plataform=..?clientid?..'. Is there a way I could retrieve this full URL generated by this GET request? Kind regards,


Solution

  • Surprisingly enough there is no direct method for getting full request string. BUT

    1. After the request is done you could check $client->getLastRequest ().
    2. If you need to know what the ?plataform=..?clientid? part of the request is there is a trick.

    function getClientUrl (Zend_Http_Client $client)
    {
        try
        {
            $c = clone $client;
            /*
             * Assume there is nothing on 80 port.
             */
            $c->setUri ('http://127.0.0.1');
    
            $c->getAdapter ()
                ->setConfig (array (
                'timeout' => 0
            ));
    
            $c->request ();
        }
        catch (Exception $e)
        {
            $string = $c->getLastRequest ();
            $string = substr ($string, 4, strpos ($string, "HTTP/1.1\r\n") - 5);
        }
        return $client->getUri (true) . $string;
    }
    
    $client = new Zend_Http_Client ('http://yahoo.com');
    $client->setParameterGet ('q', 'search string');
    
    echo getClientUrl ($client);