为何预先构建的cors策略配置在Laravel 7应用程序中不起作用? [英] Any reason why pre-build cors policy configuration not functioning in Laravel 7 application?
本文介绍了为何预先构建的cors策略配置在Laravel 7应用程序中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用axios向Laravel后端应用程序请求.它总是会抛出这些错误
I made a "post" request using axios to the Laravel back-end application. It always throws these errors
提交表格后:
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.
到目前为止我做了什么:
what I have done so far:
cors.php(laravel中的配置文件)
cors.php ( config file in 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,
];
允许原点且路径已更改.
Allow origin and the paths had been changed.
vue js axios请求
vue js axios request
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
}
},
推荐答案
感谢所有观众. 撰写者更新";命令已经解决了问题.
Thanks for all the viewers. "composer update" command has solved the problem.
这篇关于为何预先构建的cors策略配置在Laravel 7应用程序中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文