'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
时间: 2023-10-17 19:36:40 浏览: 198
域名无法访问端口80被占用
"'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource." 表示在请求的资源上没有提供 'Access-Control-Allow-Origin' 头,导致该资源无法被访问。这是由于浏览器的同源策略所引起的安全限制。同源策略要求AJAX请求只能在同一域名下进行访问,如果请求的资源位于不同的域名下,并且服务器没有设置允许跨域访问的响应头('Access-Control-Allow-Origin'),浏览器会拦截这个请求,阻止其访问。
为了解决这个问题,你可以在服务端设置响应头,允许特定的域名访问该资源。可以通过在响应头中添加 'Access-Control-Allow-Origin' 字段,并将其值设置为请求的域名,即允许该域名跨域访问该资源。如果允许多个域名访问该资源,可以使用通配符 '*' 来设置 'Access-Control-Allow-Origin' 的值。
另外,还可以设置其他的CORS相关的响应头,例如 'Access-Control-Allow-Methods' 用于指定允许的请求方法, 'Access-Control-Allow-Headers' 用于指定允许的请求头,以及 'Access-Control-Max-Age' 用于指定预检请求的缓存时间等。
请注意,在生产环境中,确保仅允许信任的域名跨域访问资源,以保护系统的安全性。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [vue用axios进行token请求出现has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ ...](https://blog.csdn.net/FHlang/article/details/115770129)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ header is present on the ...](https://blog.csdn.net/qq_45800640/article/details/118422632)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文