为啥预构建 cors 策略配置在 Laravel 7 应用程序中不起作用?
Posted
技术标签:
【中文标题】为啥预构建 cors 策略配置在 Laravel 7 应用程序中不起作用?【英文标题】:Any reason why pre-build cors policy configuration not functioning in Laravel 7 application?为什么预构建 cors 策略配置在 Laravel 7 应用程序中不起作用? 【发布时间】:2020-12-04 21:36:16 【问题描述】:我使用 axios 向 Laravel 后端应用程序发出了“发布”请求。它总是抛出这些错误
提交表格后:
Access to XMLHttpRequest at 'mydomain' (redirected from 'mydomain') from origin 'mydomain' 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.
在提交表格之前:
Cross-Origin Read Blocking (CORB) blocked cross-origin response mydomain with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
到目前为止我做了什么:
cors.php(laravel 中的配置文件)
return [
'paths' => ['api/*','web/*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [
'Cache-Control',
'Content-Language',
'Content-Type',
'Expires',
'Last-Modified',
'Pragma',
],
'max_age' => 0,
'supports_credentials' => false,
];
允许原点,路径已更改。
vue js axios 请求
const result = await this.callApi('post','/user/login', this.data)
callApi 方法
async callApi(method,url,data)
try
//axios.defaults.headers.post['Content-Type'] ='application/x-www-form-urlencoded';
// Send a POST request
return await axios(
method: method,
url: url,
data: data
);
catch (e)
return e.response
,
【问题讨论】:
【参考方案1】:感谢所有观众。 “composer update”命令解决了这个问题。
【讨论】:
以上是关于为啥预构建 cors 策略配置在 Laravel 7 应用程序中不起作用?的主要内容,如果未能解决你的问题,请参考以下文章
CORS 策略已阻止访问 XMLHttpRequest - Laravel 5.8
Laravel Sanctum:被带有 Nuxt Auth 模块的 CORS 策略阻止
Laravel 7 Passport:被 CORS 策略阻止