Symfony 为什么CORS策略仅在我转储时阻止请求?
我在我的Vue、Symfony(使用Docker进行设置)项目上遇到了问题,CORS策略阻止了我对API的请求,因此我加入了nelmio CORS包,并对其进行了设置,以便现在可以正常响应 这是我的nelmio配置:Symfony 为什么CORS策略仅在我转储时阻止请求?,symfony,vue.js,cors,dump,nelmiocorsbundle,Symfony,Vue.js,Cors,Dump,Nelmiocorsbundle,我在我的Vue、Symfony(使用Docker进行设置)项目上遇到了问题,CORS策略阻止了我对API的请求,因此我加入了nelmio CORS包,并对其进行了设置,以便现在可以正常响应 这是我的nelmio配置: nelmio_cors: defaults: origin_regex: true allow_origin: ['%env(CORS_ALLOW_ORIGIN)%'] allow_methods: ['GET', 'OPTIONS', 'POST', 'P
nelmio_cors:
defaults:
origin_regex: true
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
allow_headers: ['Content-Type', 'Authorization']
expose_headers: ['Link']
max_age: 3600
paths:
'^/': null
这是我的控制器:
/**
* @Route("/movement-types")
*/
public function getMovementTypes(MovementTypeRepository $repo): Response
{
$items = $repo->findAll();
$response = new Response();
$response->setContent(json_encode($items));
return $response;
}
到目前为止,这是可行的。但每当我将var_dump()函数的dump()添加到控制器CORS策略中时,就会再次阻止它。我试图将nelmio配置更改为最具包容性的设置,但也没有成功
nelmio_cors:
defaults:
origin_regex: true
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
allow_origin: ['*']
allow_methods: ['*']
allow_headers: ['*']
expose_headers: ['Link']
max_age: 3600
paths:
'^/': null
我也尝试过这个,尽管我认为这不是最好的解决方案。但它也不起作用。
我没有找到关于这个话题的任何其他解决方案或讨论
感谢您的帮助。我的猜测是:var_会立即转储输出,而任何bundle都会使用给定的响应对象并向其添加所需的cors头。但是,由于您已经通过转储生成了输出,因此头已经设置好,不能再由bundle设置,因此没有cors头我的猜测是:var_dump立即输出,而任何bundle都将使用给定的响应对象并向其添加所需的cors头。但是,由于您已经通过转储生成了输出,因此已经设置了头文件,不能再由bundle设置头文件,因此没有cors头文件