2012-02-07 100 views
2

我有类似的东西:如何检索完整的Zend_Http_Client GET URI?

$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? 亲切的问候,

回答

2

令人惊讶的是,没有直接的方法获取完整的请求字符串。 但

  1. 请求完成后,你可以检查$客户 - > 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); 
+0

“有招” 或 “要小心”? :) 不管怎么说,还是要谢谢你。我很惊讶没有人有过这样的需要......甚至可能会重写整个班级并添加这样的功能... – 2012-02-07 10:33:54

+0

这是一个棘手的技巧。如果你有兴趣,我可以给你一个线索。 – akond 2012-02-07 10:42:38

+0

哦,是的,请!它会帮助我很多! :) – 2012-02-07 11:17:37