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"
}
标签:index,请求,url,request,cookieName,hyperf,fullUrl,name 来源: https://www.cnblogs.com/hu308830232/p/15302244.html