hyperf 请求


控制器 app/Controller/IndexController.php

<?php
namespace App\Controller;

use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Contract\RequestInterface;

/**
 * @AutoController();
 */
class IndexController
{
        public function index(RequestInterface $request){

                SetCookie('cookie_name','cookie:huyongjian');
                //获取参数
                $name = $request->input('name','huyongjian');
                //获取请求路径
                $uri = $request->path();
                //获取url
                $url = $request->url();
                // 带上查询参数
                $fullUrl = $request->fullUrl();
                //获取请求方法
                $method = $request->getMethod();

                //获取cookie
                $cookieName = $request->cookie('name', 'Hyperf');
                return [
                        'name'=>$name,
                        'uri'=>$uri,
                        'url'=>$url,
                        'fullUrl'=>$fullUrl,
                        'method'=>$method,
                        'cookieName'=>$cookieName
                ];
        }
}

测试

curl 118.195.173.53:9501/index/index?name=huyongjian

结果

{
    "name": "huyongjian",
    "uri": "index\/index",
    "url": "http:\/\/118.195.173.53:9501\/index\/index",
    "fullUrl": "http:\/\/118.195.173.53:9501\/index\/index?name=huyongjian",
    "method": "GET",
    "cookieName": "Hyperf"
}
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM