mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
让Request支持json方式的POST
目前RESTful API用json方式提交的很多 目前PUT/PATCH/DELETE方法均可以支持json,但POST方法不能,这不对等 其实更好的方法是判断header里content-type是否为application/json,但因为目前header属性采用的是懒加载,所以暂时沿用目前的字符串判断
This commit is contained in:
@@ -686,8 +686,13 @@ class Request
|
|||||||
public function post($name = '', $default = null, $filter = '')
|
public function post($name = '', $default = null, $filter = '')
|
||||||
{
|
{
|
||||||
if (empty($this->post)) {
|
if (empty($this->post)) {
|
||||||
|
$content = $this->input;
|
||||||
|
if (empty($_POST) && strpos($content, '":')) {
|
||||||
|
$this->post = json_decode($content, true);
|
||||||
|
} else {
|
||||||
$this->post = $_POST;
|
$this->post = $_POST;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
$this->param = [];
|
$this->param = [];
|
||||||
return $this->post = array_merge($this->post, $name);
|
return $this->post = array_merge($this->post, $name);
|
||||||
|
|||||||
Reference in New Issue
Block a user