add clear
This commit is contained in:
+15
-10
@@ -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 = [])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user