正在显示
1 个修改的文件
包含
33 行增加
和
0 行删除
| @@ -64,6 +64,12 @@ class App { | @@ -64,6 +64,12 @@ class App { | ||
| 64 | private array $error = []; | 64 | private array $error = []; | 
| 65 | 65 | ||
| 66 | /** | 66 | /** | 
| 67 | + * 前端提交过来的body内容 | ||
| 68 | + * @var | ||
| 69 | + */ | ||
| 70 | + private $bodyRaw = ''; | ||
| 71 | + | ||
| 72 | + /** | ||
| 67 | * App constructor. | 73 | * App constructor. | 
| 68 | */ | 74 | */ | 
| 69 | public function __construct() | 75 | public function __construct() | 
| @@ -80,6 +86,13 @@ class App { | @@ -80,6 +86,13 @@ class App { | ||
| 80 | 86 | ||
| 81 | // 请求参数 TODO::不允许其他类型的请求参数 | 87 | // 请求参数 TODO::不允许其他类型的请求参数 | 
| 82 | $this->request = my_filter($_REQUEST,['trim']); | 88 | $this->request = my_filter($_REQUEST,['trim']); | 
| 89 | + // 提交到服务器的body 内容 | ||
| 90 | + $this->bodyRaw = file_get_contents("php://input"); | ||
| 91 | + | ||
| 92 | + $josnBody = $this->getBodyRawJson2Array(); | ||
| 93 | + if($josnBody){ | ||
| 94 | + $this->request = array_merge($josnBody,$this->request); | ||
| 95 | + } | ||
| 83 | 96 | ||
| 84 | // 调试 | 97 | // 调试 | 
| 85 | if(defined('APP_DEBUG')){ | 98 | if(defined('APP_DEBUG')){ | 
| @@ -191,6 +204,26 @@ class App { | @@ -191,6 +204,26 @@ class App { | ||
| 191 | } | 204 | } | 
| 192 | 205 | ||
| 193 | /** | 206 | /** | 
| 207 | + * body请求内容 | ||
| 208 | + * @return false|string | ||
| 209 | + * @author:dc | ||
| 210 | + * @time 2024/12/17 9:57 | ||
| 211 | + */ | ||
| 212 | + public function getBodyRaw(){ | ||
| 213 | + return $this->bodyRaw; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + /** | ||
| 217 | + * json 数据 body里面的 | ||
| 218 | + * @return mixed | ||
| 219 | + * @author:dc | ||
| 220 | + * @time 2024/12/17 9:51 | ||
| 221 | + */ | ||
| 222 | + public function getBodyRawJson2Array(){ | ||
| 223 | + return json_decode($this->bodyRaw,true) ? : []; | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + /** | ||
| 194 | * 读取数组 | 227 | * 读取数组 | 
| 195 | * @param string $name | 228 | * @param string $name | 
| 196 | * @param array $default | 229 | * @param array $default | 
- 
请 注册 或 登录 后发表评论