public function testAllParts() { $url = new Url('http://*****:*****@www.zend.com:8080/path/to/file?a=1&b=2#top'); $this->assertEquals('http', $url->getScheme()); $this->assertEquals('andi', $url->getUsername()); $this->assertEquals('password', $url->getPassword()); $this->assertEquals('www.zend.com', $url->getHost()); $this->assertEquals('8080', $url->getPort()); $this->assertEquals('/path/to/file', $url->getPath()); $this->assertEquals('a=1&b=2', $url->getQuery()); $this->assertEquals('top', $url->getFragment()); $this->assertTrue($url->isValid()); }
/** * Set the URI for the next request * * @param \Zend\Uri\Url|string $uri * @return \Zend\Http\Client * @throws \Zend\Http\Client\Exception */ public function setUri($uri) { if (is_string($uri)) { try { $uri = new Uri\Url($uri); } catch (URI\Exception $e) { throw new Client\Exception('Passed parameter is not a valid HTTP URI.'); } } $scheme = strtolower($uri->getScheme()); if (!empty($scheme) && !in_array($scheme, array('http', 'https'))) { throw new 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; }