{"id":1069,"date":"2025-06-12T11:58:19","date_gmt":"2025-06-12T03:58:19","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/symfony\/1069.html"},"modified":"2025-06-12T11:58:19","modified_gmt":"2025-06-12T03:58:19","slug":"%e5%9c%a8symfony%e4%b8%ad%e5%a4%84%e7%90%86cors%ef%bc%9a%e5%ae%9e%e7%94%a8%e6%8c%87%e5%8d%97","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/1069.html","title":{"rendered":"\u5728Symfony\u4e2d\u5904\u7406CORS\uff1a\u5b9e\u7528\u6307\u5357"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">Bug&#32534;&#35793;&#29422;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312;Symfony&#20013;&#22788;&#29702;&#36328;&#22495;&#36164;&#28304;&#20849;&#20139;&#65288;CORS&#65289;&#26159;&#19968;&#39033;&#24120;&#35265;&#30340;&#38656;&#27714;&#65292;&#29305;&#21035;&#26159;&#22312;&#26500;&#24314;Web&#24212;&#29992;&#31243;&#24207;&#26102;&#12290;CORS&#26159;&#20801;&#35768;&#27983;&#35272;&#22120;&#21521;&#26381;&#21153;&#22120;&#21457;&#20986;&#35831;&#27714;&#20197;&#33719;&#21462;&#36164;&#28304;&#30340;&#26426;&#21046;&#12290;&#19979;&#38754;&#26159;&#19968;&#20123;&#23454;&#29992;&#30340;&#27493;&#39588;&#21644;&#31034;&#20363;&#20195;&#30721;&#26469;&#24110;&#21161;&#20320;&#22312;Symfony&#39033;&#30446;&#20013;&#35774;&#32622;&#21644;&#37197;&#32622;CORS&#12290;<\/p>\n<h3>1. &#23433;&#35013;<code>symfony-cors-bundle<\/code><\/h3>\n<p>&#39318;&#20808;&#65292;&#20320;&#38656;&#35201;&#23433;&#35013;<code>symfony-cors-bundle<\/code>&#36825;&#20010;Bundle&#12290;&#20320;&#21487;&#20197;&#20351;&#29992;Composer&#26469;&#23436;&#25104;&#36825;&#19968;&#28857;&#65306;<\/p>\n<pre><code class=\"language-bash\">composer require symfony\/cors-bundle<\/code><\/pre>\n<p>&#23433;&#35013;&#23436;&#25104;&#21518;&#65292;&#20320;&#38656;&#35201;&#22312;<code>config\/bundles.php<\/code>&#25991;&#20214;&#20013;&#27880;&#20876;<code>CorsBundle<\/code>&#65306;<\/p>\n<pre><code class=\"language-php\">\/\/ config\/bundles.php\n\nreturn [\n    \/\/ &#20854;&#20182;Bundle...\n\n    SymfonyBundleCorsBundleCorsBundle::class =&gt; ['all' =&gt; true],\n];<\/code><\/pre>\n<h3>2. &#37197;&#32622;CORS<\/h3>\n<p>&#25509;&#19979;&#26469;&#65292;&#20320;&#38656;&#35201;&#22312;<code>config\/packages\/cors.yaml<\/code>&#25991;&#20214;&#20013;&#37197;&#32622;CORS&#12290;&#20197;&#19979;&#26159;&#19968;&#20010;&#22522;&#26412;&#30340;&#37197;&#32622;&#31034;&#20363;&#65306;<\/p>\n<pre><code class=\"language-yaml\">\n# config\/packages\/cors.yaml\n\ncors:\n    defaults:\n        origin: '*'\n        allow_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allow_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', 'DELETE']\n        allowed_headers: ['Origin', 'Content-Type', 'Accept', 'Authorization']\n        expose_headers: []\n        max_age: 3600\n        hosts: []\n        paths: [\"\/api\/**\"]\n        allowed_origins: [\"\/\"]\n        allowed_methods: ['GET', 'POST', 'PUT', '<\/code><\/pre>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;Bug&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#40657;&#26495;Bug&#35762;&#24072;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><h2>&#20171;&#32461;<\/h2><p>&#36328;&#22495;&#36164;&#28304;&#20849;&#20139;&#65288;CORS&#65289;&#26159;&#19968;&#31181;&#23433;&#20840;&#21151;&#33021;&#65292;&#20801;&#35768;&#25110;&#38480;&#21046;&#20174;&#19981;&#21516;&#22495;&#21517;&#35831;&#27714;&#36164;&#28304;&#12290;&#24403;&#32593;&#31449;&#30340;&#21069;&#31471;&#21644;&#21518;&#31471;&#20998;&#21035;&#22312;&#19981;&#21516;&#30340;&#22495;&#21517;&#19978;&#36816;&#34892;&#26102;&#65292;&#36825;&#26159;&#24320;&#21457;&#32773;&#38754;&#20020;&#30340;&#19968;&#20010;&#24120;&#35265;&#25361;&#25112;&#12290;<\/p><p>&#36825;&#31687;&#25991;&#31456;&#23558;&#20026;&#24744;&#25552;&#20379;&#22914;&#20309;&#22312;Symfony&#24212;&#29992;&#20013;&#22788;&#29702;CORS&#30340;&#27493;&#39588;&#25351;&#21335;&#65292;&#36825;&#26159;&#19968;&#20010;&#24191;&#27867;&#20351;&#29992;&#30340;PHP&#26694;&#26550;&#12290;&#25105;&#20204;&#23558;&#20171;&#32461;CORS&#30340;&#22522;&#26412;&#27010;&#24565;&#12289;&#35774;&#32622;Symfony&#39033;&#30446;&#20197;&#21450;&#22312;&#24212;&#29992;&#31243;&#24207;&#20013;&#37197;&#32622;CORS&#12290;<\/p><h2>&#29702;&#35299;CORS&#65288;&#36328;&#28304;&#36164;&#28304;&#20849;&#20139;&#65289;<\/h2><p>CORS&#65288;&#36328;&#28304;&#36164;&#28304;&#20849;&#20139;&#65289;&#26159;&#19968;&#31181;HTTP&#21327;&#35758;&#65292;&#20801;&#35768;&#26381;&#21153;&#22120;&#25351;&#23450;&#38500;&#33258;&#36523;&#22495;&#21517;&#12289;&#26041;&#26696;&#25110;&#31471;&#21475;&#22806;&#30340;&#20854;&#20182;&#26469;&#28304;&#65292;&#20197;&#20801;&#35768;&#27983;&#35272;&#22120;&#21152;&#36733;&#36164;&#28304;&#12290;&#22914;&#26524;&#22312;CORS&#37197;&#32622;&#20013;&#26410;&#36827;&#34892;&#35774;&#32622;&#25110;&#32773;&#37197;&#32622;&#19981;&#20801;&#35768;&#35831;&#27714;&#65292;&#21017;&#27983;&#35272;&#22120;&#20250;&#38459;&#27490;&#21069;&#31471;JavaScript&#20195;&#30721;&#21521;&#19981;&#21516;&#26469;&#28304;&#21457;&#36215;&#35831;&#27714;&#12290;<\/p><p>&#19968;&#20010;CORS&#35831;&#27714;&#30340;&#31034;&#20363;&#26159;&#22312;&#30001;&#24744;&#30340;React&#25110;Angular&#24212;&#29992;&#31243;&#24207;&#29983;&#25104;&#30340;&#23458;&#25143;&#31471;&#22495;&#65288;yourdomain.com&#65289;&#35831;&#27714;&#26469;&#33258;api.domain.com&#65288;&#26381;&#21153;&#22120;&#22495;&#65289;&#30340;&#36164;&#28304;&#26102;&#21457;&#29983;&#30340;&#24773;&#20917;&#12290;<\/p><h2>&#35774;&#32622;Symfony<\/h2><p>&#22914;&#26524;&#20320;&#36824;&#27809;&#26377;&#35774;&#32622;&#22909;Symfony&#39033;&#30446;&#65292;&#21487;&#20197;&#22312;&#32456;&#31471;&#20013;&#36816;&#34892;&#20197;&#19979;&#21629;&#20196;&#26469;&#21019;&#24314;&#19968;&#20010;&#65306;<\/p><pre><code>composer create-project symfony\/skeleton your_project_name<\/code><\/pre><p>&#30830;&#20445;&#24744;&#24050;&#32463;&#23433;&#35013;&#20102;Composer&#65292;&#36825;&#26159;&#19968;&#20010;PHP&#21253;&#31649;&#29702;&#24037;&#20855;&#12290;<\/p><h2>&#22312;Symfony&#20013;&#21551;&#29992;CORS&#65288;&#36328;&#28304;&#36164;&#28304;&#20849;&#20139;&#65289;&#12290;<\/h2><p>Symfony &#19981;&#33258;&#24102; CROS &#25903;&#25345;&#65292;&#20294;&#20320;&#21487;&#20197;&#36890;&#36807;&#31616;&#21333;&#22320;&#28155;&#21152;&#23427;&#26469;&#23454;&#29616;&#12290;<code>nelmio\/cors-bundle<\/code>&#22909;&#30340;&#65292;&#35831;&#21457;&#36865;&#20320;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p><pre><code>composer require nelmio\/cors-bundle<\/code><\/pre><p>&#23433;&#35013;&#21518;&#65292;&#36890;&#36807;&#32534;&#36753;&#26469;&#37197;&#32622;&#23427;&#12290;<code>config\/packages\/nelmio_cors.yaml<\/code>&#26681;&#25454;&#24744;&#30340;Symfony&#29256;&#26412;&#65292;&#24212;&#20351;&#29992;&#36866;&#24403;&#30340;&#37197;&#32622;&#25991;&#20214;&#12290;<\/p><pre><code>nelmio_cors:\n    defaults:\n        origin_regex: true\n        allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']\n        allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']\n        allow_headers: ['Content-Type', 'Authorization']\n        expose_headers: ['Link']\n        max_age: 3600\n    paths:\n        '^\/api\/': null\n<\/code><\/pre><p>&#20320;&#21487;&#20197;&#26681;&#25454;&#20219;&#20309;&#25351;&#23450;&#30340;&#36335;&#24452;&#27169;&#24335;&#33258;&#23450;&#20041;CORS&#35774;&#32622;&#12290;&#36825;&#37324;&ldquo;null&rdquo;&#34920;&#31034;&#23427;&#20250;&#20351;&#29992;&#40664;&#35748;&#20540;&#12290;&#24744;&#36824;&#21487;&#20197;&#36890;&#36807;&#29615;&#22659;&#21464;&#37327;&#21160;&#24577;&#35774;&#32622;&#36825;&#20123;&#12290;<code>allow_origin<\/code>&#20215;&#20540;&#12290;<\/p><h2>&#22788;&#29702;CORS&#65288;&#36328;&#28304;&#36164;&#28304;&#20849;&#20139;&#65289;&#22312;&#25511;&#21046;&#22120;&#20013;&#30340;&#23454;&#29616;&#12290;<\/h2><p>&#24744;&#21487;&#33021;&#38656;&#35201;&#30452;&#25509;&#22312;&#25511;&#21046;&#22120;&#20013;&#35843;&#25972;CORS&#22836;&#20197;&#23454;&#29616;&#26356;&#31934;&#32454;&#30340;&#25511;&#21046;&#65292;&#25110;&#32773;&#22312;&#24320;&#21457;&#29615;&#22659;&#20013;&#36825;&#26679;&#20570;&#12290;&#20320;&#21487;&#20197;&#36825;&#26679;&#25805;&#20316;&#65306;<\/p><pre><code>use SymfonyComponentHttpFoundationResponse;\n\nclass YourController\n{\n    public function yourAction()\n    {\n        \/\/ .. perform some logic\n        $response = new Response();\n        $response-&gt;headers-&gt;set('Access-Control-Allow-Origin', '*');\n        \/\/ Set other CORS headers as needed\n        return $response;\n    }\n}\n<\/code><\/pre><p>&#27880;&#24847;&#65306;&#35774;&#32622;&ldquo;Access-Control-Allow-Origin&rdquo;&#22836;&#20026;&ldquo;*&rdquo;&#65292;&#20801;&#35768;&#26469;&#33258;&#20219;&#20309;&#26469;&#28304;&#30340;&#35831;&#27714;&#12290;&#36825;&#22312;&#20844;&#20849;API&#19978;&#26159;&#21487;&#20197;&#25509;&#21463;&#30340;&#65292;&#20294;&#22312;&#20351;&#29992;&#26102;&#24212;&#35880;&#24910;&#12290;<\/p><h2>&#27979;&#35797;&#24744;&#30340;CORS&#37197;&#32622;<\/h2><p>&#19968;&#26086;&#35774;&#32622;&#20102;CORS&#65292;&#23601;&#38656;&#35201;&#27979;&#35797;&#20197;&#30830;&#20445;&#20854;&#27491;&#24120;&#24037;&#20316;&#12290;&#20320;&#21487;&#20197;&#20351;&#29992;&#21508;&#31181;&#24037;&#20855;&#26469;&#36827;&#34892;&#27492;&#25805;&#20316;&#65306;<\/p><p>Curl &#21629;&#20196;&#21487;&#20197;&#27169;&#25311;&#26469;&#33258;&#19981;&#21516;&#26469;&#28304;&#30340;&#35831;&#27714;&#65292;&#20197;&#26816;&#26597;&#24744;&#30340;&#26381;&#21153;&#22120;&#21709;&#24212;&#22836;&#12290;<\/p><p>&#20687;test-cors.org&#36825;&#26679;&#30340;&#22312;&#32447;&#26381;&#21153;&#20801;&#35768;&#24744;&#23545;&#24744;&#30340;&#22495;&#21517;&#25191;&#34892;CORS&#65288;&#36328;&#28304;&#36164;&#28304;&#20849;&#20139;&#65289;&#35831;&#27714;&#24182;&#26597;&#30475;&#32467;&#26524;&#12290;<\/p><p>&#27983;&#35272;&#22120;&#24320;&#21457;&#24037;&#20855;&#20801;&#35768;&#24744;&#26816;&#26597;&#32593;&#32476;&#35831;&#27714;&#24182;&#26597;&#30475;CORS&#22836;&#20449;&#24687;&#12290;<\/p><pre><code>curl -H \"Origin: http:\/\/yourdomain.com\" \n     -H \"Access-Control-Request-Method: POST\" \n     -X OPTIONS --verbose \n     http:\/\/apidomain.com\/api\/resource\n<\/code><\/pre><p>&#27983;&#35272;&#22120;&#20250;&#26174;&#31034;&#29992;&#20110;&#30830;&#23450;&#23454;&#38469;&#35831;&#27714;&#26159;&#21542;&#23433;&#20840;&#30340;&#22836;&#37096;&#12290;<\/p><h2>&#32467;&#35770;&#12290;<\/h2><p>&#22312;Symfony&#20013;&#23454;&#29616;CORS&#38750;&#24120;&#31616;&#21333;&#65292;&#21487;&#20197;&#36890;&#36807;&#20351;&#29992;&#31532;&#19977;&#26041;&#21253;&#22914;NelmioCorsBundle&#26469;&#23436;&#25104;&#12290;&#35813;&#21253;&#20445;&#30041;&#20102;&#22788;&#29702;CORS&#21327;&#35758;&#30340;&#35768;&#22810;&#22797;&#26434;&#24615;&#12290;&#22312;&#37197;&#32622;CORS&#26102;&#65292;&#35831;&#22987;&#32456;&#36981;&#24490;&#26368;&#23567;&#29305;&#26435;&#21407;&#21017;&#65292;&#20165;&#20801;&#35768;&#38656;&#35201;&#19982;&#19981;&#21516;&#36215;&#28304;&#36890;&#20449;&#30340;&#20855;&#20307;&#20869;&#23481;&#12290;&#36328;&#28304;&#23433;&#20840;&#23545;&#20110;&#24212;&#29992;&#31243;&#24207;&#30340;&#25972;&#20307;&#36136;&#37327;&#21644;&#23433;&#20840;&#24615;&#33267;&#20851;&#37325;&#35201;&#12290;<\/p><p>&#27979;&#35797;CORS&#35774;&#32622;&#20063;&#26159;&#24517;&#19981;&#21487;&#23569;&#30340;&#65292;&#30830;&#20445;&#19968;&#20999;&#36816;&#34892;&#27491;&#24120;&#19988;&#19981;&#26292;&#38706;&#24744;&#30340;&#24212;&#29992;&#31243;&#24207;&#21040;&#19981;&#24517;&#35201;&#30340;&#39118;&#38505;&#12290;&#26681;&#25454;&#25552;&#20379;&#30340;&#25351;&#23548;&#36827;&#34892;&#22788;&#29702;CORS&#22312;Symfony&#20013;&#30340;&#25805;&#20316;&#24212;&#35813;&#26159;&#24744;&#21487;&#20197;&#26500;&#24314;&#26356;&#24378;&#22823;&#21644;&#23433;&#20840;&#30340;&#24212;&#29992;&#31243;&#24207;&#30340;&#19968;&#20010;&#21487;&#35775;&#38382;&#20219;&#21153;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--3\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/xygcfznnzczhsdmwydzhsmzzzmddnq-400x300.jpg\" alt=\"&#38271;&#24037;&#30721;&#22900;1523\" class=\"wp-image-2906\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#38271;&#24037;&#30721;&#22900;1523<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; Symfony &#20013;&#35774;&#32622; CORS&#65288;&#36328;&#28304;&#36164;&#28304;&#20849;&#20139;&#65289;&#21151;&#33021;&#26159;&#19968;&#31181;&#22686;&#24378;&#24212;&#29992;&#23433;&#20840;&#24615;&#30340;&#26041;&#27861;&#12290;&#23427;&#20801;&#35768;&#27983;&#35272;&#22120;&#20174;&#20854;&#20182;&#26381;&#21153;&#22120;&#35831;&#27714;&#36164;&#28304;&#65292;&#32780;&#19981;&#20250;&#31435;&#21363;&#19979;&#36733;&#25972;&#20010;&#21709;&#24212;&#20307;&#12290;&#36825;&#26377;&#21161;&#20110;&#38450;&#27490;&#26410;&#32463;&#35768;&#21487;&#30340;&#36328;&#31449;&#28857;&#33050;&#26412;&#25915;&#20987;&#12290;<\/p>\n<h3>&#23454;&#29992;&#25351;&#21335;<\/h3>\n<h4>1. &#35774;&#32622; CORS &#31574;&#30053;<\/h4>\n<p>&#35201;&#20026; Symfony &#24212;&#29992;&#37197;&#32622; CORS&#65292;&#35831;&#25353;&#29031;&#20197;&#19979;&#27493;&#39588;&#25805;&#20316;&#65306;<\/p>\n<ul>\n<li>\n<p><strong>&#23433;&#35013; CORS &#36335;&#30001;&#22788;&#29702;&#22120;<\/strong>&#65306;<\/p>\n<pre><code class=\"language-bash\">composer require symfony\/http-foundation:&gt;=5.4<\/code><\/pre>\n<\/li>\n<li>\n<p>&#22312; <code>app\/config\/config.yml<\/code> &#25991;&#20214;&#20013;&#28155;&#21152; CORS &#37197;&#32622;&#65306;<\/p>\n<pre><code class=\"language-yaml\">cors:\nallow-all: true\nallowed-others: true\nallowed-origin-patterns: 'http:\/\/www.example.com\/*'<\/code><\/pre>\n<\/li>\n<li>\n<p>&#20351;&#29992; <code>CorsMiddleware<\/code> &#32465;&#23450;&#21040;&#25511;&#21046;&#22120;&#21644;&#35270;&#22270;&#12290;<\/p>\n<pre><code class=\"language-php\">use SymfonyBundleFrameworkBundleControllerAbstractController;\nuse SymfonyComponentHttpFoundationResponse;\nuse SymfonyContractsHttpClientHttpClientInterface;\nuse SymfonyContractsHttpKernelExceptionAccessDeniedHttpException;\n\nclass MyController extends AbstractController\n{\n  private $httpClient;\n\n  public function __construct(HttpClientInterface $client)\n  {\n      $this-&gt;httpClient = $client;\n  }\n\n  \/\/ ... &#20854;&#20182;&#25511;&#21046;&#22120;&#20989;&#25968; ...\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<h4>2. &#27979;&#35797; CORS &#35774;&#32622;<\/h4>\n<p>&#20026;&#20102;&#27979;&#35797; CORS &#35774;&#32622;&#26159;&#21542;&#27491;&#30830;&#24037;&#20316;&#65292;&#21487;&#20197;&#20351;&#29992; Postman &#25110;&#31867;&#20284;&#30340;&#24037;&#20855;&#26469;&#21457;&#36215;&#19968;&#20010; CORS &#35831;&#27714;&#12290;&#20363;&#22914;&#65292;&#35775;&#38382; <code>http:\/\/localhost:8000\/cors-test<\/code> &#24182;&#23581;&#35797;&#21457;&#36865;&#19968;&#20010; GET &#35831;&#27714;&#12290;&#22914;&#26524;&#19968;&#20999;&#27491;&#24120;&#65292;&#24744;&#24212;&#35813;&#33021;&#30475;&#21040;&#26469;&#33258;&#26381;&#21153;&#22120;&#30340;&#21709;&#24212;&#12290;<\/p>\n<h3>&#31034;&#20363;&#20195;&#30721;<\/h3>\n<p>&#19979;&#38754;&#25552;&#20379;&#20102;&#19968;&#20010;&#31616;&#21333;&#30340;&#20363;&#23376;&#65292;&#23637;&#31034;&#22914;&#20309;&#20351;&#29992; Symfony &#30340; HTTP &#23458;&#25143;&#31471; API &#21457;&#36215; CORS &#35831;&#27714;&#65306;<\/p>\n<pre><code class=\"language-php\">use SymfonyComponentHttpFoundationRequest;\nuse SymfonyComponentHttpFoundationResponse;\nuse SymfonyContractsHttpClientHttpClientInterface;\nuse SymfonyContractsHttpKernelExceptionAccessDeniedHttpException;\n\nclass CorsTestController\n{\n    private $httpClient;\n\n    public function __construct(HttpClientInterface $client)\n    {\n        $this-&gt;httpClient = $client;\n    }\n\n    public function testAction(Request $request): Response\n    {\n        try {\n            $response = $this-&gt;httpClient-&gt;sendRequest(\n                Request::METHOD_GET,\n                \"http:\/\/localhost:8000\/cors-test\"\n            );\n\n            return new Response(\"Hello, World!\", 200);\n        } catch (AccessDeniedHttpException $e) {\n            throw new AccessDeniedHttpException();\n        }\n    }\n}<\/code><\/pre>\n<p>&#36890;&#36807;&#36825;&#31181;&#26041;&#24335;&#65292;&#24744;&#21487;&#20197;&#26681;&#25454;&#38656;&#35201;&#33258;&#23450;&#20041; CORS &#35774;&#32622;&#65292;&#24182;&#30830;&#20445;&#24744;&#30340;&#24212;&#29992;&#31243;&#24207;&#19982; Web &#23433;&#20840;&#31574;&#30053;&#20445;&#25345;&#19968;&#33268;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312;Symfony&#20013;&#22788;&#29702;&#36328;&#22495;&#36164;&#28304;&#20849;&#20139;&#65288;CORS&#65289;&#26159;&#19968;&#39033;&#038;..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[45],"tuisongtax":[],"class_list":["post-1069","my1js","type-my1js","status-publish","hentry","my1js2nav-symfony"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/1069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=1069"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=1069"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=1069"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=1069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}