【发布时间】:2020-09-30 20:46:40
【问题描述】:
我得到这个错误:
从源“http://localhost:8080”访问“http://127.0.0.1:8000/api/user”处的 XMLHttpRequest 已被 CORS 策略阻止:“Access-Control-Allow-Origin”标头的值“http://localhost:8080/*”不相等到提供的原点。
我已经创建了中间件,没有任何改变:
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin','http://localhost:8080/*')
->header('Access-Control-Allow-Methods','POST,PUT,GET,DELETE,OPTIONS')
->header('Access-Control-Allow-Headers','Accept,Authorization,Content-Type')
->header('Content-Type','application/json');
}
【问题讨论】: