From a1a4c857bb720a9745a3865bc837db9b60eccdfd Mon Sep 17 00:00:00 2001 From: Karson Date: Thu, 22 May 2025 16:41:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=B9=E6=B3=95=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 4baf026a..07213335 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -521,19 +521,24 @@ class Request // 获取原始请求类型 return $this->server('REQUEST_METHOD') ?: 'GET'; } elseif (!$this->method) { - if (isset($_POST[Config::get('var_method')])) { - $method = strtoupper($_POST[Config::get('var_method')]); + $varMethod = Config::get('var_method'); + if ($varMethod && isset($_POST[$varMethod])) { + $method = strtoupper($_POST[$varMethod]); if (in_array($method, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) { $this->method = $method; $this->{$this->method}($_POST); } else { $this->method = 'POST'; } - unset($_POST[Config::get('var_method')]); - } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { - $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); + unset($_POST[$varMethod]); } else { - $this->method = $this->server('REQUEST_METHOD') ?: 'GET'; + $method = $this->server('REQUEST_METHOD') ?: 'GET'; + $httpMethodOverride = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ?? ''); + if ($method === 'POST' && in_array($httpMethodOverride, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) { + $this->method = $httpMethodOverride; + } else { + $this->method = $method; + } } } return $this->method;