From 07803dd31a9b657258e287e22183d3fb0b29c8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 25 Nov 2020 16:55:23 +0800 Subject: [PATCH] add clear --- wchat/common/HttpClient.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/wchat/common/HttpClient.php b/wchat/common/HttpClient.php index 9271756..18958c2 100644 --- a/wchat/common/HttpClient.php +++ b/wchat/common/HttpClient.php @@ -680,21 +680,22 @@ class HttpClient if ($this->method == self::POST) { curl_setopt($ch, CURLOPT_POST, 1); } - if ($this->method == self::GET || !empty($this->_data)) { - if (!is_string($this->_data)) { - $message = $this->header['Content-Type'] ?? $this->header['content-type'] ?? 'application/json'; - if ($message == 'application/json') { - $this->_data = json_encode($this->_data, JSON_UNESCAPED_UNICODE); - } else { - $this->_data = http_build_query($this->_data); - } - } - curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_data); - } else { - curl_setopt($ch, CURLOPT_POSTFIELDS, $this->mergeParams($data)); - } + if ($this->method != self::GET && !empty($this->_data)) { + $this->_data = $this->mergeParams($data); + } curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($this->method)); + + if (!is_string($this->_data)) { + $message = $this->header['Content-Type'] ?? $this->header['content-type'] ?? 'application/json'; + if ($message == 'application/json') { + $this->_data = json_encode($this->_data, JSON_UNESCAPED_UNICODE); + } else { + $this->_data = http_build_query($this->_data); + } + } + curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_data); + $output = curl_exec($ch); if ($output === false) { throw new Exception(curl_error($ch));