如何从Laravel 5的HTTP响应中获取自定义标头? [英] How to get custom header from HTTP response in Laravel 5?

查看:636
本文介绍了如何从Laravel 5的HTTP响应中获取自定义标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Laravel中的Request访问自定义标头.标头名称为"accessing_from".列出Laravel中的所有标头,只给我提供标准标头",但是我设置的标头不在列表中.在浏览器的网络"标签中,我可以看到标题已发送.所以我想知道如何从Laravel中访问它.

I'm trying to access a custom header from the Request in Laravel. The header name is "accessing_from". Listing all the headers in Laravel, gives me only the "standard ones", but the one that I've set isn't present in the list. Checking in the browser network tab I can see that the header gets sent. So I'm wondering how to access it from within Laravel.

我正在使用Angular2通过默认的http服务发出请求.

I'm using Angular2 to make the request with the default http service.

感谢任何人!

推荐答案

您是在谈论get参数还是什么?如果是这样,请使用:

Are you talking about get parameter or something? If so, use:

request()->accessing_from;

对于标题,您应该使用:

For header you should use:

request()->header('accessing_from');

为此的可行解决方案是daver的答案(最后一个): Laravel获取请求标头

The working solution for this was the answer (the last one) of daver here: Laravel get request header

这篇关于如何从Laravel 5的HTTP响应中获取自定义标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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