本文整理汇总了PHP中Guzzle\Http\Message\Request::setPort方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setPort方法的具体用法?PHP Request::setPort怎么用?PHP Request::setPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Request
的用法示例。
在下文中一共展示了Request::setPort方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRequestHasPort
/**
* @covers Guzzle\Http\Message\Request::getPort
* @covers Guzzle\Http\Message\Request::setPort
*/
public function testRequestHasPort()
{
$this->assertEquals(8124, $this->request->getPort());
$this->assertEquals('127.0.0.1:8124', $this->request->getHeader('Host'));
$this->assertEquals($this->request, $this->request->setPort('8080'));
$this->assertEquals('8080', $this->request->getPort());
$this->assertEquals('127.0.0.1:8080', $this->request->getHeader('Host'));
$this->request->setPort(80);
$this->assertEquals('127.0.0.1', $this->request->getHeader('Host'));
}
示例2: testCanChangePortThroughScheme
public function testCanChangePortThroughScheme()
{
$request = new Request('GET', 'http://foo.com');
$request->setScheme('https');
$this->assertEquals('https://foo.com', (string) $request->getUrl());
$this->assertEquals('foo.com', $request->getHost());
$request->setScheme('http');
$this->assertEquals('http://foo.com', (string) $request->getUrl());
$this->assertEquals('foo.com', $request->getHost());
$request->setPort(null);
$this->assertEquals('http://foo.com', (string) $request->getUrl());
$this->assertEquals('foo.com', $request->getHost());
}
示例3: generateRequest
protected function generateRequest($url, array $subProtocols, array $headers)
{
$headers = array_merge($this->defaultHeaders, $headers);
$headers['Sec-WebSocket-Key'] = $this->generateKey();
$request = new Request('GET', $url, $headers);
$scheme = strtolower($request->getScheme());
if (!in_array($scheme, ['ws', 'wss'])) {
throw new \InvalidArgumentException(sprintf('Cannot connect to invalid URL (%s)', $url));
}
$request->setScheme('HTTP');
if (!$request->getPort()) {
$request->setPort('wss' === $scheme ? 443 : 80);
} else {
$request->setHeader('Host', $request->getHeader('Host') . ":{$request->getPort()}");
}
if (!$request->getHeader('Origin')) {
$request->setHeader('Origin', str_replace('ws', 'http', $scheme) . '://' . $request->getHost());
}
// do protocol headers
if (count($subProtocols) > 0) {
$protocols = implode(',', $subProtocols);
if ($protocols != "") {
$request->setHeader('Sec-WebSocket-Protocol', $protocols);
}
}
return $request;
}