From 1cf50602178ce38734e7430e9f01b1e3129a4071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 18 Nov 2020 14:41:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Client/ClientAbstracts.php | 13 ++++++++----- HttpServer/Client/Curl.php | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/HttpServer/Client/ClientAbstracts.php b/HttpServer/Client/ClientAbstracts.php index 257117ad..924f4b8c 100644 --- a/HttpServer/Client/ClientAbstracts.php +++ b/HttpServer/Client/ClientAbstracts.php @@ -190,12 +190,15 @@ abstract class ClientAbstracts extends Component implements IClient */ public function setHost(string $host): void { - if (!preg_match('/(\d{1,3}\.){4}/', $host . '.')) { - $this->addHeader('Host', $host); + $this->host = $host; + if ($this->use_swoole) { $this->host = System::gethostbyname($host); - } else { - $this->host = $host; } + $this->addHeader('Host', $host); +// +// if (!preg_match('/(\d{1,3}\.){4}/', $host . '.')) { +// } else { +// } } /** @@ -762,7 +765,7 @@ abstract class ClientAbstracts extends Component implements IClient } else if (strpos($string, '/') !== 0) { $string = '/' . $string; } - return [$host, false, $string]; + return [$host, $this->isSSL(), $string]; } diff --git a/HttpServer/Client/Curl.php b/HttpServer/Client/Curl.php index b01ddd3b..6f8221b1 100644 --- a/HttpServer/Client/Curl.php +++ b/HttpServer/Client/Curl.php @@ -40,6 +40,8 @@ class Curl extends ClientAbstracts { [$host, $isHttps, $path] = $this->matchHost($path); + $host = $isHttps ? 'https://' . $host : 'http://' . $host; + $resource = $this->do(curl_init($host . $path), $host . $path, $method); if ($method === self::POST && !empty($params)) { curl_setopt($resource, CURLOPT_POSTFIELDS, HttpParse::parse($params)); @@ -64,6 +66,8 @@ class Curl extends ClientAbstracts { [$host, $isHttps, $path] = $this->matchHost($path); + $host = $isHttps ? 'https://' . $host : 'http://' . $host; + $resource = $this->do(curl_init($host . $path), $host . $path, self::POST); curl_setopt($resource, CURLOPT_POSTFIELDS, $params);