尝试在 Controller 中获取header 授权 key 以制作API。 fiddler 发出请求。
$headers = apache_request_headers();
$header 包含一个数组。
Array
(
[User-Agent] => Fiddler
[Host] => localhost:8000
[Content-Length] => 102
[Authorization] => TestKey
)
如果我这样尝试获取 Authorization ,它会抛出错误。
$header['Authorization]
错误:
Undefined index: Authorization
尝试了很多方法来获得授权,但没有任何效果。有什么办法可以获取这个吗?
最佳答案
要从请求中获取 header ,您应该使用 Request 类
public function yourControllerFunction(\Illuminate\Http\Request $request)
{
$header = $request->header('Authorization');
// do some stuff
}
参见 https://laravel.com/api/5.5/Illuminate/Http/Request.html#method_header
关于php - 在 laravel Controller 中获取标题授权 key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37001665/