接口在dev环境报跨域问题(has been blocked by CORS policy:Response to preflight request doesn't pass access control check:No 'Access-Control-Allow-Origin' header ispresent on the requested resource.),qa环境正常


前端报错:

has been blocked by CORS policy: Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.

跨域问题,解决办法:(主要是后端解决)

     在对应的接口处,设置允许跨域即可

在对应的 Controller 上加上 @CrossOrigin 注解,或者在 springBoot 里面写一个配置类实现全局跨域:

// 服务端代码
@SpringBootConfiguration
public class MyWebConfigurer implements WebMvcConfigurer{
@Override
public void addCorsMappings(CorsRegistry corsRegistry){
/**
* 所有请求都允许跨域,使用这种配置就不需要
* 在 interceptor 中配置 header 了
*/
corsRegistry.addMapping('/**')
.allowCredentials(true)
.allowedOrigins('http://localhost:8080')
.allowedMethods('POST','GET','PUT','OPTIONS','DELETE')
.allowedHeaders('*')
.maxAge(3600);
}
}
以上代码是摘字参考链接里面的,突然觉得服务端超有趣,哈哈

 

参考链接:https://www.cnblogs.com/Courage129/p/14005223.html

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed a 跨域请求错误: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource [Nginx] 解决跨域been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 跨域报错has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request. 跨域详解 been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource 跨域详解 been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource nginx 实现 ajax 跨域请求Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin ajax post上传数据时,前端出现的跨域权限问题:ccess to XMLHttpRequest at ‘’rom origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok st
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM