From b8e4a80c3ad14c9b828c4ee1d001f9922ebb3c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 8 May 2020 19:03:11 +0800 Subject: [PATCH] add clear --- wchat/common/HttpClient.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/wchat/common/HttpClient.php b/wchat/common/HttpClient.php index be90da8..ce37bb6 100644 --- a/wchat/common/HttpClient.php +++ b/wchat/common/HttpClient.php @@ -2,6 +2,7 @@ namespace wchat\common; +use Exception; use Swoole\Coroutine\Http\Client as SClient; use Swoole\Coroutine\System; use Swoole\Coroutine\Client; @@ -283,7 +284,7 @@ class HttpClient * @param $url * @param array $data * @return array|mixed|Result - * @throws \Exception + * @throws Exception */ private function request($url, $data = []) { @@ -305,7 +306,8 @@ class HttpClient /** * @param string $string - * @return bool|mixed + * @return bool|string + * @throws Exception */ private function matchHost($string = '') { @@ -343,7 +345,7 @@ class HttpClient } if (!$this->checkIsIp($this->host) && !$this->isDomainName($this->host)) { - throw new \Exception('Client Host error.'); + throw new Exception('Client Host error.'); } return $string; @@ -430,7 +432,7 @@ class HttpClient * @param $url * @param array $data * @return array|mixed|Result - * @throws \Exception + * @throws Exception * 使用swoole协程方式请求 */ private function coroutine($url, $data = []) @@ -438,7 +440,7 @@ class HttpClient try { $client = $this->generate_client($this->host, $url, $data); if ($client->statusCode < 0) { - throw new \Exception($client->errMsg); + throw new Exception($client->errMsg); } unset($this->_data); @@ -546,6 +548,9 @@ class HttpClient { if (!is_array($data)) { $data = Help::toArray($data); + if (is_string($data)) { + return $data; + } } $contentType = $this->header['Content-Type'] ?? 'application/json'; if (strpos($contentType, 'json') !== false) { @@ -611,7 +616,7 @@ class HttpClient * @param $url * @param $data * @return bool|string - * @throws \Exception + * @throws Exception */ private function curlParse($url, $data) { @@ -647,7 +652,7 @@ class HttpClient curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($this->method)); $output = curl_exec($ch); if ($output === false) { - throw new \Exception(curl_error($ch)); + throw new Exception(curl_error($ch)); } curl_close($ch); return $output; @@ -872,7 +877,7 @@ class HttpClient * @param $url * @param array $data * @return array|mixed|Result - * @throws \Exception + * @throws Exception */ public function option($url, $data = []) { @@ -884,7 +889,7 @@ class HttpClient * @param $url * @param array $data * @return array|mixed|Result - * @throws \Exception + * @throws Exception */ public function delete($url, $data = []) { @@ -896,7 +901,7 @@ class HttpClient * @param $url * @param array $data * @return array|mixed|Result - * @throws \Exception + * @throws Exception */ public function send($url, $data = []) {