Laravel 自定义中间件解决跨域问题 header 头不生效,有人解决过此类问题吗?
中间件核心代码如下:
public function handle($request, Closure $next)
{
$response = $next($request);
//允许请求来自哪些域名
$response->header('Access-Control-Allow-Origin', '*');
//允许请求中包含哪些header
$response->header('Access-Control-Allow-Headers', 'token,Origin, X-Requested-With, Content-Type, Accept');
//允许请求采用哪些请求方式
$response->header('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
//允许请求中携带cookie
$response->header('Access-Control-Allow-Credentials', 'true');
//自定义的请求头token
$response->header('Access-Control-Expose-Headers', 'token');
return $response;
}
问题描述:
添加了header头 token时 报不允许Origin
不添加header头 token时 不同域名之间接口可以正常请求
关于 LearnKu
要不试试我的?
@BANice 我的是自定义了一个header头 token不行 不自定义header头没问题
可以
@ThinkCsly 你测试可以?
碰到了同样的问题,只要是header里添加的自定义的内容就会跨域失败 楼主问题怎么解决的