如何在 Laravel 中基于 application/json 标头加载路由
问题描述
I'm using the application/json
header to control how my controller acts when a request is received. I need for the POST in my unit test to include an application/json
header.
I've tried:
And it the Request::isJson()
in my controller continues to return false.
I also tried using 'CONTENT_TYPE' => 'application/json'
instead of the HTTP_CONTENT_TYPE
above.
In my case, I was using Content-Type
to determine which controllers to load. This didn't work for me, because routes are loaded into memory when TestCase->createApplication()
is run. This means my headers had no effect.
I ended up making a RouteInflector
that allows me to force my tests to use the Api routes.
Inflector:
这篇关于如何在 Laravel 中基于 application/json 标头加载路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!