企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
>[danger] 该组件为系统组件,在组件树中只可命名为 request ,不可修改为其他名称。 ## 请求 请求组件用来获取所有HTTP请求参数。 | 类 | 调用 | 运行环境 | | --- | --- | --- | | Mix\Http\Message\Request\HttpRequest | app()->request | mix-httpd | | Mix\Http\Message\Request\Compatible\HttpRequest | app()->request | Apache/PHP-FPM | ## 依赖注入配置 [>> 到 GitHub 查看默认配置 <<](https://github.com/mix-php/mix/blob/v2/applications/http/config/main_coroutine.php#L178) ## 获取参数 | 方法 | 描述 | | --- | --- | | route | 获取路由参数 | | get | 获取 $_GET 参数 | | post | 获取 $_POST 参数 | | files | 获取 $_FILES 参数 | | server | 获取 $_SERVER 参数 (全部小写) | | header | 获取 HEADER 参数 (全部小写) | | getRawBody | 返回原始的 HTTP 包体 | >[success] 以上所有方法变量名不存在时返回 null。 ## 请求类型 | 方法 | 描述 | | --- | --- | | method | 返回请求类型 | | isGet | 是否为 GET 请求 | | isPost | 是否为 POST 请求 | | isPut | 是否为 PUT 请求 | | isPatch | 是否为 PATCH 请求 | | isDelete | 是否为 DELETE 请求 | | isHead | 是否为 HEAD 请求 | | isOptions | 是否为 OPTIONS 请求 | ## 请求路径 | 方法 | 描述 | | --- | --- | | root | 返回请求的域名 | | path | 返回请求的路径 | | url | 返回请求的URL | | fullUrl | 返回请求的完整URL | ## 获取路由参数 ~~~ // 获取单个参数 app()->request->route('name'); // 获取所有参数,返回数组 app()->request->route(); ~~~ ## 获取 `GET` 参数 ~~~ // 获取单个参数 app()->request->get('name'); // 获取所有参数,返回数组 app()->request->get(); ~~~ ## 获取 `POST` 参数 ~~~ // 获取单个参数 app()->request->post('name'); // 获取所有参数,返回数组 app()->request->post(); ~~~ ## 获取 `FILES` 参数 ~~~ // 获取单个参数 app()->request->files('name'); // 获取所有参数,返回数组 app()->request->files(); ~~~ ## 获取 `SERVER` 参数 ~~~ // 获取单个参数 app()->request->server('name'); // 获取所有参数,返回数组 app()->request->server(); ~~~ ## 获取 `HEADER ` 参数 ~~~ // 获取单个参数 app()->request->header('name'); // 获取所有参数,返回数组 app()->request->header(); ~~~ ## 返回原始的 `HTTP` 包体 ~~~ app()->request->getRawBody(); ~~~ ## 返回请求路径 ~~~ app()->request->root(); // http//www.domain.com app()->request->path(); // index/index.html app()->request->url(); // http//www.domain.com/index/index.html app()->request->fullUrl(); // http//www.domain.com/index/index.html?s=hello ~~~