2

私はそのようなものを持っています:

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

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

これにより、「http://www.site.com/?plataform=..?clientid?..」のようなリクエストが生成されます。この GET 要求によって生成されたこの完全な URL を取得する方法はありますか? 敬具、

4

1 に答える 1

2

驚くべきことに、完全なリクエスト文字列を直接取得する方法はありません。しかし

  1. リクエストが完了したら、 $client->getLastRequest () を確認できます。
  2. ?plataform=..?clientid? リクエストの一部にはトリックがあります。

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);
于 2012-02-07T09:51:39.970 に答える