From e435a3888b6e9a6a80a91ebb6e8ce7d2097e8e08 Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Fri, 3 Jan 2020 15:12:06 +0800 Subject: [PATCH] add clear --- common/HttpClient.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/common/HttpClient.php b/common/HttpClient.php index 2466593..2e1fe7e 100644 --- a/common/HttpClient.php +++ b/common/HttpClient.php @@ -431,21 +431,34 @@ class HttpClient return new Result(['code' => 500, 'message' => curl_error($ch)]); } - [$header, $body] = explode("\r\n\r\n", $output); - $header = explode(PHP_EOL, $header); - - $status = (int)explode(' ', trim($header[0]))[1]; - $header = $this->headerFormat($header); + [$header, $body, $status] = $this->explode($output); if ($status != 200) { return new Result(['code' => 500, 'message' => $body, 'header' => $header]); } - return $this->structure($this->resolve($header, $body), $data, $header); + return $this->structure($body, $data, $header); } catch (\Exception $exception) { return new Result(['code' => 500, 'message' => $exception->getMessage(), 'header' => []]); } } + /** + * @param $output + * @return array + */ + private function explode($output) + { + [$header, $body] = explode("\r\n\r\n", $output, 2); + $header = explode(PHP_EOL, $header); + + unset($output); + + $status = (int)explode(' ', trim($header[0]))[1]; + $header = $this->headerFormat($header); + + return [$header, $this->resolve($header, $body), $status]; + } + /** * @param $url * @param $data