Laravel获取请求头 [英] Laravel get request headers

查看:91
本文介绍了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.

我想像这样获得Authorization标头:

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()));

,并注意到它不包含任何Authorization标头.只需托管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}]

这篇关于Laravel获取请求头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆