has been blocked by CORS policy: No Access-Control-Allow-Origin header is present on the requested resource.
时间: 2023-10-15 13:26:18 浏览: 722
corsyusha:简单快速的代理,可在针对现有API进行原型设计时绕过CORS问题,而不必担心CORS
这个错误信息说明在发送请求时,服务器返回的响应头中没有包含Access-Control-Allow-Origin字段,导致浏览器拒绝接受该响应。这是由于跨域访问(Cross-Origin Resource Sharing,CORS)的限制所引起的。
为了解决这个问题,可以添加一个名为CorsConfig的配置类,其中配置了允许跨域访问的规则。具体做法是使用addCorsMappings方法将允许跨域访问的规则添加到CorsRegistry中,可以设置allowedOriginPatterns为"*",表示允许来自所有域的请求;allowedHeaders设置为CorsConfiguration.ALL,表示允许所有请求头;allowedMethods设置为CorsConfiguration.ALL,表示允许所有请求方法;allowCredentials设置为true,表示允许发送身份验证信息;maxAge设置为3600,表示设置响应缓存的最大时间。通过这个配置类,服务器会在响应头中添加Access-Control-Allow-Origin字段,从而允许跨域访问。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [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_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [corsyusha:简单快速的代理,可在针对现有API进行原型设计时绕过CORS问题,而不必担心CORS](https://download.csdn.net/download/weixin_42176612/18261495)[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_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [解决前后端跨域报错:has been blocked by CORS policy: No ‘Access-Control-Allow-Origin](https://blog.csdn.net/wsaicyj/article/details/127814374)[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_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文