[英]Laravel POST request Cors No 'Access-Control-Allow-Origin'
Currently receiving an error message when I attempt to POST to a given url. 当我尝试发布到给定的URL时,当前收到一条错误消息。 GET works fine on the same domain here is my error:
GET在同一域上工作正常,这是我的错误:
Access to XMLHttpRequest at ' http://localhost:8000/api/users/login ' from origin ' http://localhost:8080 ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
已从CORS策略阻止从原点' http:// localhost:8080 '访问' http:// localhost:8000 / api / users / login '上的XMLHttpRequest:对预检请求的响应未通过访问控制检查:否“ Access-Control-Allow-Origin”标头存在于请求的资源上。
I've found countless questions documenting this same issue all with variations of modify my Cors middleware. 我发现无数问题记录了相同的问题,并且都修改了我的Cors中间件。
Currently my CORS middleware looks like this: 目前,我的CORS中间件如下所示:
class Cors
{
public function handle($request, Closure $next)
{
if ($request->isMethod('OPTIONS')) {
$response = Response::make();
} else {
$response = $next($request);
}
return $response
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, Application');
}
}
The error states No 'Access-Control-Allow-Origin' which I believe my ->header('Access-Control-Allow-Origin', '*')
should handle since the * is a wild card from my understanding. 错误表明没有'Access-Control-Allow-Origin',我认为我的
->header('Access-Control-Allow-Origin', '*')
应该处理,因为从我的理解来看,*是通配符。 Is there a different issue at play here I'm missing? 我想念的这里还有其他问题吗? Stack is Laravel backend with VueJS front end using Axios for HTTP requests if that is relevant.
如果相关的话,Stack是Laravel后端,VueJS前端使用Axios进行HTTP请求。
Edit: This question is unique in that I already have the headers suggested in most answers specifically: 编辑:这个问题是独特的,因为我已经有大多数答案中具体建议的标题:
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
and am still getting the error. 并仍然出现错误。
Here are two packages which can help you handling CORS in Laravel, you can choose one 这是两个可以帮助您在Laravel中处理CORS的软件包,您可以选择一个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.