Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 访问静态文件时跨源请求被阻止错误_Laravel_Cors - Fatal编程技术网

Laravel 访问静态文件时跨源请求被阻止错误

Laravel 访问静态文件时跨源请求被阻止错误,laravel,cors,Laravel,Cors,我正在使用Laravel开发一个api,在react frontend中,我想通过api读取一个pdf文件,但它给了我以下错误: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). 这是我的cors.php(水果蛋糕/laravel cors包

我正在使用Laravel开发一个api,在react frontend中,我想通过api读取一个pdf文件,但它给了我以下错误:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
这是我的cors.php(水果蛋糕/laravel cors包)


或者您可以尝试添加以下内容:

header('Access-Control-Allow-Origin:');标题('Access-Control-Allow-Methods:');标题('Access-Control-Allow-Headers:')在您的bootstrap/app.php中。希望这能解决您的问题

如果您的API出现错误,也可能会发生这种情况。可能是这样,但API会在直接链接上正确返回数据。我认为pdf文件返回了一个错误,因为其他api路由工作正常(用于显示数据和图像)。希望这能对你有所帮助。
<?php

return [

    'paths' => ['*'],

    'allowed_methods' => ['*'],

    'allowed_origins' => ['*'],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => false,

    'max_age' => false,

    'supports_credentials' => false,

];