diff --git a/wchat/common/HttpClient.php b/wchat/common/HttpClient.php index 3e4ef0f..607f39b 100644 --- a/wchat/common/HttpClient.php +++ b/wchat/common/HttpClient.php @@ -283,9 +283,6 @@ class HttpClient $data = $this->paramEncode($data); if ($this->use_swoole) { $url = $this->matchHost($url); - if (!$this->checkIsIp($this->host)) { - $this->host = System::gethostbyname($this->host); - } return $this->coroutine($this->host, $url, $data); } else { return $this->useCurl($url, $data); @@ -309,18 +306,27 @@ class HttpClient if (empty($string)) { return false; } - $string = str_replace('http://', '', $string); + // 手动设置请求域名 + if (!empty($this->host)) { + if (!$this->checkIsIp($this->host)) { + $this->host = System::gethostbyname($this->host); + } + return $string; + } + + // 替换请求头为空 + $string = str_replace('http://', '', $string); if ($this->isHttps($string)) { $string = str_replace('https://', '', $string); - $this->isSSL = true; - $this->port = 443; + $this->setIsSSL(true); } $hostAndUrls = explode('/', $string); if (empty($hostAndUrls)) { return false; } + $this->host = array_shift($hostAndUrls); $hostAndUrls = implode('/', $hostAndUrls); if (strpos($this->host, ':') !== false) { @@ -329,9 +335,13 @@ class HttpClient return '/' . $hostAndUrls; } } + if (!$this->isDomainName($this->host)) { return false; } + + $this->host = System::gethostbyname($this->host); + return '/' . $hostAndUrls; }