您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-路由-路由接口-head请求
发布时间:2022-01-19 22:34:50编辑:雪饮阅读()
head请求postman会直接报错,而用curl则可以的。
config/route.php进行路由注册:
Route::head('/blog/{id}', [app\controller\Foo::class, 'index'])->name('blog.view');
\app\controller\Foo.php控制器实现:
<?php
namespace app\controller;
use support\Request;
class Foo
{
/**
* 该方法会在请求前调用
*/
public function beforeAction(Request $request)
{
echo 'beforeAction';
// 若果想终止执行Action就直接返回Response对象,不想终止则无需return
// return response('终止执行Action');
}
/**
* 该方法会在请求后调用
*/
public function afterAction(Request $request, $response)
{
echo 'afterAction';
// 如果想串改请求结果,可以直接返回一个新的Response对象
// return response('afterAction');
}
public function index(Request $request,$id)
{
return response(route('blog.view', ['id' => 100]));
}
public function index2(Request $request)
{
return response('foo index2');
}
public function edit2(Request $request)
{
return response('foo edit2');
}
public function notFound(Request $request)
{
return response('i am so sorry:页面未找到!');
}
}
head请求实例:
[root@localhost ~]# curl --location --head 'http://192.168.31.53:8787/blog/djp'
HTTP/1.1 200 OK
Server: workerman
Content-Type: text/html;charset=utf-8
Content-Length: 9
Connection: keep-alive
关键字词:webman,header,請求,路由,接口