Laravel get request headers(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}]
这篇关于Laravel 获取请求头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 获取请求头


基础教程推荐
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的PDF导出 2022-01-01
- php中的foreach复选框POST 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01