「日常报错」Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

说明

在使用 axios 进行 ajax 请求时,发生跨域错误。后端使用 SpringBoot,已经加上 @CrossOrigin 注解

原因

浏览器的预检请求失败,即 OPTION 请求失败,根据你的后端放行 OPTION 请求即可

解决方案

// Spring Security 中放行 option 请求
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()

其他后端自行查询如何放行 OPTION 请求即可

原文地址:https://www.cnblogs.com/posase/p/12903951.html