Reactjs 授权Laravel中的ERR_EMPTY_响应错误

Reactjs 授权Laravel中的ERR_EMPTY_响应错误,reactjs,laravel,axios,cloudflare,Reactjs,Laravel,Axios,Cloudflare,我有一个使用Laravel的web服务,它解决了CORS源问题,但下一个问题是具有授权头的请求返回以下错误服务器 OPTIONS/api/v1/user/net profile::ERR\u EMPTY\u响应 我目前正在使用cloudflare,想知道这是CDN还是服务器上的其他内容。这是飞行前请求。 您需要允许选项请求。首先,您需要创建CORS中间件 <?php namespace App\Http\Middleware; use Closure; cla

我有一个使用Laravel的web服务,它解决了CORS源问题,但下一个问题是具有授权头的请求返回以下错误服务器

OPTIONS/api/v1/user/net profile::ERR\u EMPTY\u响应


我目前正在使用cloudflare,想知道这是CDN还是服务器上的其他内容。

这是飞行前请求。 您需要允许选项请求。首先,您需要创建CORS中间件

<?php

    namespace App\Http\Middleware;

    use Closure;

    class Cors
    {
        public function handle($request, Closure $next)
        {
            $headers = [
                'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
                'Access-Control-Allow-Headers'=> 'X-Requested-With, Content-Type, Accept, Origin, Authorization',
                'Access-Control-Allow-Origin' => '*'
            ];

            if($request->getMethod() === 'OPTIONS') {
                // The client-side application can set only headers allowed in Access-Control-Allow-Headers
                return \response('', 200, $headers);
            }

            $response = $next($request);
            foreach($headers as $key => $value)
                $response->header($key, $value);
            return $response;
        }
    }

之后,所有带有类型选项的请求将返回带有标题的响应200。

这是飞行前请求。 您需要允许选项请求。首先,您需要创建CORS中间件

<?php

    namespace App\Http\Middleware;

    use Closure;

    class Cors
    {
        public function handle($request, Closure $next)
        {
            $headers = [
                'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
                'Access-Control-Allow-Headers'=> 'X-Requested-With, Content-Type, Accept, Origin, Authorization',
                'Access-Control-Allow-Origin' => '*'
            ];

            if($request->getMethod() === 'OPTIONS') {
                // The client-side application can set only headers allowed in Access-Control-Allow-Headers
                return \response('', 200, $headers);
            }

            $response = $next($request);
            foreach($headers as $key => $value)
                $response->header($key, $value);
            return $response;
        }
    }
之后,所有带有类型选项的请求将返回带有标题的响应200