From df6aa119a06f584bc2ee76d7627cc21bf72c34af Mon Sep 17 00:00:00 2001 From: testadmin Date: Thu, 14 May 2026 11:40:54 +0800 Subject: [PATCH] fix: use getContent() for JSON body parsing in log endpoint --- app/handle/controller/Log.php | 7 +++++-- app/index/controller/Log.php | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/handle/controller/Log.php b/app/handle/controller/Log.php index 5037bb9..de61361 100644 --- a/app/handle/controller/Log.php +++ b/app/handle/controller/Log.php @@ -11,8 +11,11 @@ class Log public function report(): Json { if (!Request::instance()->isPost()) return json(['status' => 0]); - $raw = file_get_contents('php://input'); - $data = json_decode($raw, true) ?: Request::instance()->post(); + $data = Request::instance()->post(); + if (empty($data)) { + $raw = Request::instance()->getContent(); + $data = json_decode($raw, true) ?: []; + } \app\utils\Logger::error(\app\utils\Logger::CAT_FRONTEND, $data['message'] ?? 'unknown', [ 'source' => $data['source'] ?? 'unknown', 'type' => $data['type'] ?? 'error', diff --git a/app/index/controller/Log.php b/app/index/controller/Log.php index 8062ef5..a6147ec 100644 --- a/app/index/controller/Log.php +++ b/app/index/controller/Log.php @@ -11,8 +11,11 @@ class Log public function report(): Json { if (!Request::instance()->isPost()) return json(['status' => 0]); - $raw = file_get_contents('php://input'); - $data = json_decode($raw, true) ?: Request::instance()->post(); + $data = Request::instance()->post(); + if (empty($data)) { + $raw = Request::instance()->getContent(); + $data = json_decode($raw, true) ?: []; + } \app\utils\Logger::error(\app\utils\Logger::CAT_FRONTEND, $data['message'] ?? 'unknown', [ 'source' => $data['source'] ?? 'unknown', 'type' => $data['type'] ?? 'error',