add clear
This commit is contained in:
+15
-10
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace wchat\common;
|
namespace wchat\common;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Swoole\Coroutine\Http\Client as SClient;
|
use Swoole\Coroutine\Http\Client as SClient;
|
||||||
use Swoole\Coroutine\System;
|
use Swoole\Coroutine\System;
|
||||||
use Swoole\Coroutine\Client;
|
use Swoole\Coroutine\Client;
|
||||||
@@ -283,7 +284,7 @@ class HttpClient
|
|||||||
* @param $url
|
* @param $url
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array|mixed|Result
|
* @return array|mixed|Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function request($url, $data = [])
|
private function request($url, $data = [])
|
||||||
{
|
{
|
||||||
@@ -305,7 +306,8 @@ class HttpClient
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $string
|
* @param string $string
|
||||||
* @return bool|mixed
|
* @return bool|string
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function matchHost($string = '')
|
private function matchHost($string = '')
|
||||||
{
|
{
|
||||||
@@ -343,7 +345,7 @@ class HttpClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->checkIsIp($this->host) && !$this->isDomainName($this->host)) {
|
if (!$this->checkIsIp($this->host) && !$this->isDomainName($this->host)) {
|
||||||
throw new \Exception('Client Host error.');
|
throw new Exception('Client Host error.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
@@ -430,7 +432,7 @@ class HttpClient
|
|||||||
* @param $url
|
* @param $url
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array|mixed|Result
|
* @return array|mixed|Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
* 使用swoole协程方式请求
|
* 使用swoole协程方式请求
|
||||||
*/
|
*/
|
||||||
private function coroutine($url, $data = [])
|
private function coroutine($url, $data = [])
|
||||||
@@ -438,7 +440,7 @@ class HttpClient
|
|||||||
try {
|
try {
|
||||||
$client = $this->generate_client($this->host, $url, $data);
|
$client = $this->generate_client($this->host, $url, $data);
|
||||||
if ($client->statusCode < 0) {
|
if ($client->statusCode < 0) {
|
||||||
throw new \Exception($client->errMsg);
|
throw new Exception($client->errMsg);
|
||||||
}
|
}
|
||||||
unset($this->_data);
|
unset($this->_data);
|
||||||
|
|
||||||
@@ -546,6 +548,9 @@ class HttpClient
|
|||||||
{
|
{
|
||||||
if (!is_array($data)) {
|
if (!is_array($data)) {
|
||||||
$data = Help::toArray($data);
|
$data = Help::toArray($data);
|
||||||
|
if (is_string($data)) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$contentType = $this->header['Content-Type'] ?? 'application/json';
|
$contentType = $this->header['Content-Type'] ?? 'application/json';
|
||||||
if (strpos($contentType, 'json') !== false) {
|
if (strpos($contentType, 'json') !== false) {
|
||||||
@@ -611,7 +616,7 @@ class HttpClient
|
|||||||
* @param $url
|
* @param $url
|
||||||
* @param $data
|
* @param $data
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function curlParse($url, $data)
|
private function curlParse($url, $data)
|
||||||
{
|
{
|
||||||
@@ -647,7 +652,7 @@ class HttpClient
|
|||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($this->method));
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($this->method));
|
||||||
$output = curl_exec($ch);
|
$output = curl_exec($ch);
|
||||||
if ($output === false) {
|
if ($output === false) {
|
||||||
throw new \Exception(curl_error($ch));
|
throw new Exception(curl_error($ch));
|
||||||
}
|
}
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
return $output;
|
return $output;
|
||||||
@@ -872,7 +877,7 @@ class HttpClient
|
|||||||
* @param $url
|
* @param $url
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array|mixed|Result
|
* @return array|mixed|Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function option($url, $data = [])
|
public function option($url, $data = [])
|
||||||
{
|
{
|
||||||
@@ -884,7 +889,7 @@ class HttpClient
|
|||||||
* @param $url
|
* @param $url
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array|mixed|Result
|
* @return array|mixed|Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function delete($url, $data = [])
|
public function delete($url, $data = [])
|
||||||
{
|
{
|
||||||
@@ -896,7 +901,7 @@ class HttpClient
|
|||||||
* @param $url
|
* @param $url
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array|mixed|Result
|
* @return array|mixed|Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function send($url, $data = [])
|
public function send($url, $data = [])
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user