Laravel 获取请求头

2021-12-29 00:00:00 oauth-2.0 php laravel

我正在使用 POSTMAN 将 GET 请求发送到带有包含授权的标头的 api 中.

I am using POSTMAN to send a GET request into the api with a header containing Authorization.

我知道数据头有效,因为如果无效,路由会返回 401 错误.

I know the data header works because if it doesn't the route returns a 401 error.

我想像这样获得授权标头:

I wanted to get the Authorization header like so:

$access_token = Request::header('Authorization');

但注意到它返回NULL.

But noticed that it returns NULL.

所以我试图用以下方法捕捉值:

So I tried to catch the values with:

die(var_dump(Request::header()));

并注意到它不包含任何授权标头.只需托管到 cookie 标头.

And noticed that it doesn't contain any Authorization header. Just host to cookie headers.

更新

应该得到Authorization: Bearer ACCESS TOKEN

推荐答案

你用的是什么 POSTMAN 版本?

What POSTMAN Version did you use?

您是在本地计算机还是托管服务器上,某些托管公司不允许使用 AUTHORIZATION HEADER.

Are you on your local machine or managed server, some hosting companies don't allow AUTHORIZATION HEADER.

.htaccess 修改

 RewriteEngine On
 RewriteCond %{HTTP:Authorization} .
 RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

相关文章