2

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,

1 Answers1

2

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);
akond
  • 15,865
  • 4
  • 35
  • 55
  • "There is a trick" or "is tricky"? :) Thanks anyway. I am amazed nobody ever had such need... might even worth to rewrite the whole class and add such functionality... –  Feb 07 '12 at 10:33
  • It's a tricky trick. I can give you a clue, if you're interested. – akond Feb 07 '12 at 10:42
  • Oh, yes please! It would help me a lot! :) –  Feb 07 '12 at 11:17
  • The idea was to open connection to the server itself and read HTTP header from the socket. But I forgot that I can't have threads in PHP, and Zend_Http_Client will block script execution. Thus, only firs method remains. – akond Feb 07 '12 at 12:44
  • However, if you don't want to initiate a request to remote server, you can create dumb service on your own server, and retrieve $client->getLastRequest () afterward. – akond Feb 07 '12 at 12:47