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