gpt4 book ai didi

php - 在 laravel Controller 中获取标题授权 key ?

转载 作者:IT王子 更新时间:2023-10-29 01:23:48 26 4
gpt4 key购买 nike

尝试在 Controller 中获取header 授权 key 以制作APIfiddler 发出请求。

$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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com