Zend_Http_Client::setUri PHP Method

setUri() public method

Set the URI for the next request
public setUri ( Zend_Uri_Http | string $uri ) : Zend_Http_Client
$uri Zend_Uri_Http | string
return Zend_Http_Client
    public function setUri($uri)
    {
        if ($uri instanceof Zend_Uri_Http) {
            // clone the URI in order to keep the passed parameter constant
            $uri = clone $uri;
        } elseif (is_string($uri)) {
            $uri = Zend_Uri::factory($uri);
        }
        if (!$uri instanceof Zend_Uri_Http) {
            /** @see Zend_Http_Client_Exception */
            require_once 'Zend/Http/Client/Exception.php';
            throw new Zend_Http_Client_Exception('Passed parameter is not a valid HTTP URI.');
        }
        // Set auth if username and password has been specified in the uri
        if ($uri->getUsername() && $uri->getPassword()) {
            $this->setAuth($uri->getUsername(), $uri->getPassword());
        }
        // We have no ports, set the defaults
        if (!$uri->getPort()) {
            $uri->setPort($uri->getScheme() == 'https' ? 443 : 80);
        }
        $this->uri = $uri;
        return $this;
    }

Usage Example

 public function mailgunRequest($type, $domain, $apiKey, $data, $method = Zend_Http_Client::GET, $uriOveride = false)
 {
     $client = new Zend_Http_Client();
     $client->setAuth("api", $apiKey);
     $client->setMethod($method);
     if ($uriOveride) {
         $client->setUri($uriOveride);
     } else {
         $client->setUri($this->apiUrl . $domain . "/" . $type);
     }
     if ($method == Zend_Http_Client::POST) {
         foreach ($data as $key => $value) {
             $client->setParameterPost($key, $value);
         }
     } else {
         foreach ($data as $key => $value) {
             $client->setParameterGet($key, $value);
         }
     }
     try {
         $response = $client->request();
         if ($response->getStatus() == 200) {
             return json_decode($response->getBody());
         } else {
             throw new Zend_Http_Exception("Error connecting to MailGun API. Returned error code: " . $response->getStatus() . " --- " . $response->getBody());
         }
     } catch (Exception $e) {
         Mage::logException($e);
         return false;
     }
 }
All Usage Examples Of Zend_Http_Client::setUri