本文整理汇总了PHP中Guzzle\Http\Message\Request::setHost方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setHost方法的具体用法?PHP Request::setHost怎么用?PHP Request::setHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Request
的用法示例。
在下文中一共展示了Request::setHost方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCatchesAllHostHeaderChanges
/**
* @covers Guzzle\Http\Message\Request::changedHeader
* @covers Guzzle\Http\Message\Request::setHeader
*/
public function testCatchesAllHostHeaderChanges()
{
// Tests setting using headers
$this->request->setHeader('Host', 'www.abc.com');
$this->assertEquals('www.abc.com', $this->request->getHost());
$this->assertEquals('www.abc.com:8124', $this->request->getHeader('Host'));
$this->assertEquals(8124, $this->request->getPort());
// Tests setting using setHost()
$this->request->setHost('abc.com');
$this->assertEquals('abc.com', $this->request->getHost());
$this->assertEquals('abc.com:8124', $this->request->getHeader('Host'));
$this->assertEquals(8124, $this->request->getPort());
// Tests setting with a port
$this->request->setHost('abc.com:8081');
$this->assertEquals('abc.com', $this->request->getHost());
$this->assertEquals('abc.com:8081', $this->request->getHeader('Host'));
$this->assertEquals(8081, $this->request->getPort());
// Tests setting with a port using the Host header
$this->request->setHeader('Host', 'solr.com:8983');
$this->assertEquals('solr.com', $this->request->getHost());
$this->assertEquals('solr.com:8983', (string) $this->request->getHeader('Host'));
$this->assertEquals(8983, $this->request->getPort());
// Tests setting with an inferred 443 port using the Host header
$this->request->setScheme('https');
$this->request->setHeader('Host', 'solr.com');
$this->assertEquals('solr.com', $this->request->getHost());
$this->assertEquals('solr.com:8983', (string) $this->request->getHeader('Host'));
$this->assertEquals(8983, $this->request->getPort());
}
示例2: testRequestHasHost
public function testRequestHasHost()
{
$this->assertEquals('127.0.0.1', $this->request->getHost());
$this->assertEquals('127.0.0.1:8124', (string) $this->request->getHeader('Host'));
$this->assertSame($this->request, $this->request->setHost('www2.google.com'));
$this->assertEquals('www2.google.com', $this->request->getHost());
$this->assertEquals('www2.google.com:8124', (string) $this->request->getHeader('Host'));
$this->assertSame($this->request, $this->request->setHost('www.test.com:8081'));
$this->assertEquals('www.test.com', $this->request->getHost());
$this->assertEquals(8081, $this->request->getPort());
}