From dd384422a7b33aee6d738046b8ce1da2bc5364a0 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 29 Dec 2016 12:05:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index b8bcb512..bbc635a6 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -688,7 +688,7 @@ class Request { if (empty($this->post)) { $content = $this->input; - if (empty($_POST) && 'json' == $this->type()) { + if (empty($_POST) && 'application/json' == $this->contentType()) { $this->post = (array) json_decode($content, true); } else { $this->post = $_POST; @@ -713,7 +713,7 @@ class Request { if (is_null($this->put)) { $content = $this->input; - if ('json' == $this->type()) { + if ('application/json' == $this->contentType()) { $this->put = (array) json_decode($content, true); } else { parse_str($content, $this->put); @@ -1348,6 +1348,21 @@ class Request return $this->server('REMOTE_PORT'); } + /** + * 当前请求 HTTP_CONTENT_TYPE + * @access public + * @return string + */ + public function contentType() + { + $contentType = $this->server('HTTP_CONTENT_TYPE'); + if ($contentType) { + list($type) = explode(';', $contentType); + return trim($type); + } + return ''; + } + /** * 获取当前请求的路由信息 * @access public