add clear

This commit is contained in:
as2252258@163.com
2019-12-18 20:08:51 +08:00
parent 6148a56126
commit daba7fe499
+15
View File
@@ -25,6 +25,8 @@ class HttpClient
private $ssl_cert_file = '';
private $ssl_key_file = '';
private $port = 80;
const POST = 'post';
const GET = 'get';
const PUT = 'put';
@@ -171,6 +173,13 @@ class HttpClient
public function setIsSSL(bool $isSSL)
{
$this->isSSL = $isSSL;
$this->port = 443;
}
public function setPort($port)
{
$this->port = $port;
}
/**
@@ -239,6 +248,9 @@ class HttpClient
$explode = explode('/', $url);
$first = array_shift($explode);
if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $first)) {
if (strpos($first, ':') !== false) {
[$first, $this->port] = explode(':', $first);
}
return $first;
}
return System::gethostbyname($first);
@@ -306,6 +318,9 @@ class HttpClient
*/
private function getHostPort()
{
if (!empty($this->port)) {
return $this->port;
}
$port = 80;
if ($this->isSSL) $port = 443;
return $port;