tp5 为什么获取不到header下的Authorization

浏览:1660 发布日期:2020/03/22 分类:求助交流 关键字: tp5 header Authorization
.htaccess 文件已经设置过了,
$header = Request::instance()->header();
var_dump($header);
可以正常获取到包含 Authorization的数组,
但是改为 var_dump($header['authorization']);
就报错了,提示 未定义数组索引: Authorization
但是其他的打印其他的索引缺没问题
是不是,Authorization 这个需要特殊处理
postman 可以正常接受,在浏览器是提示会报错,是不是需要在返回请求前 添加什么
-------------目前解决了,但不知道原因---------------
请求前,添加了下面这些代码if($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){

            //  解决预请求OPTIONS
            header('Access-Control-Allow-Origin:*');
            header('Access-Control-Allow-Headers:Accept,Referer,Host,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type,Cookie,Token,authorization');
            header('Access-Control-Allow-Credentials:true');
            header('Access-Control-Allow-Methods:GET,POST,OPTIONS');
            header('Access-Control-Max-Age:1728000');
            header('Content-Type:text/plain charset=UTF-8');
            header('Content-Length: 0', true);
            header('status: 200');
            header('HTTP/1.0 204 No Content');
            exit;
        }else{

            //   获取ajax请求header
            header('Access-Control-Allow-Origin:*');   //允许跨域请求的域名
            header('Access-Control-Allow-Credentials: true');
            header("Access-Control-Allow-Methods:GET, POST, PUT,DELETE,POSTIONS");   //  允许跨域请求的方式
            header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie,Token,authorization");    //  将前端自定义的header头名称写入,红色部分
         }

       //获取自定义Token的值    以tp5.1接收方式为例。

      $token = Request::header('authorization');
最佳答案
评论( 相关
后面还有条评论,点击查看>>