add clear

This commit is contained in:
2020-04-03 18:31:29 +08:00
parent f8103f93b9
commit a67ecd7493
+16 -6
View File
@@ -283,9 +283,6 @@ class HttpClient
$data = $this->paramEncode($data); $data = $this->paramEncode($data);
if ($this->use_swoole) { if ($this->use_swoole) {
$url = $this->matchHost($url); $url = $this->matchHost($url);
if (!$this->checkIsIp($this->host)) {
$this->host = System::gethostbyname($this->host);
}
return $this->coroutine($this->host, $url, $data); return $this->coroutine($this->host, $url, $data);
} else { } else {
return $this->useCurl($url, $data); return $this->useCurl($url, $data);
@@ -309,18 +306,27 @@ class HttpClient
if (empty($string)) { if (empty($string)) {
return false; 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)) { if ($this->isHttps($string)) {
$string = str_replace('https://', '', $string); $string = str_replace('https://', '', $string);
$this->isSSL = true; $this->setIsSSL(true);
$this->port = 443;
} }
$hostAndUrls = explode('/', $string); $hostAndUrls = explode('/', $string);
if (empty($hostAndUrls)) { if (empty($hostAndUrls)) {
return false; return false;
} }
$this->host = array_shift($hostAndUrls); $this->host = array_shift($hostAndUrls);
$hostAndUrls = implode('/', $hostAndUrls); $hostAndUrls = implode('/', $hostAndUrls);
if (strpos($this->host, ':') !== false) { if (strpos($this->host, ':') !== false) {
@@ -329,9 +335,13 @@ class HttpClient
return '/' . $hostAndUrls; return '/' . $hostAndUrls;
} }
} }
if (!$this->isDomainName($this->host)) { if (!$this->isDomainName($this->host)) {
return false; return false;
} }
$this->host = System::gethostbyname($this->host);
return '/' . $hostAndUrls; return '/' . $hostAndUrls;
} }