简体   繁体   English

Laravel POST请求更正否'Access-Control-Allow-Origin'

[英]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的软件包,您可以选择一个


  1. https://github.com/barryvdh/laravel-cors https://github.com/barryvdh/laravel-cors
  2. https://github.com/spatie/laravel-cors https://github.com/spatie/laravel-cors

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel Cors Access-Control-Allow-Origin - Laravel Cors Access-Control-Allow-Origin Laravel 上的 CORS (Access-Control-Allow-Origin) - CORS (Access-Control-Allow-Origin) on Laravel Laravel 生产,CORS 无“访问控制允许来源” header - Laravel Production, CORS No 'Access-Control-Allow-Origin' header header('Access-Control-Allow-Origin:*'); 不允许CORS请求 - header('Access-Control-Allow-Origin: *'); Not allowing CORS request CORS没有'Access-Control-Allow-Origin'标头存在,但OPTIONS和POST请求却得到200,但 - CORS Getting No 'Access-Control-Allow-Origin' header is present but OPTIONS and POST request get 200 but Laravel7 CORS:被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否 'Access-Control-Allow-Origin' - Laravel7 CORS : blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' Laravel CORS - 对预检请求的响应未通过访问控制检查:没有“Access-Control-Allow-Origin” header 出现在请求中 - Laravel CORS -Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested Laravel Ajax请求,没有“ Access-Control-Allow-Origin”标头 - Laravel Ajax request, No 'Access-Control-Allow-Origin' header 没有“Access-Control-Allow-Origin”标头 - Laravel - No 'Access-Control-Allow-Origin' header - Laravel Laravel API和Ionic 2客户端:CORS没有“ Access-Control-Allow-Origin”标头 - Laravel API and Ionic 2 Client: CORS No 'Access-Control-Allow-Origin' header
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM