解决前后端跨域报错:has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘

一、报错信息

has been blocked by CORS policy: No 'A***ess-Control-Allow-Origin'
 header is present on the requested resource.

来自一个IP端口的页面(前端项目),要访问另一个IP端口的资源(springboot请求接口),会产生跨域访问。

二、解决方法:增加配置类CorsConfig

@Configuration
public class CorsConfig implements WebMv***onfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedHeaders(CorsConfiguration.ALL)
                .allowedMethods(CorsConfiguration.ALL)
                .allowCredentials(true)
                .maxAge(3600);
    }
}
转载请说明出处内容投诉
CSS教程_站长资源网 » 解决前后端跨域报错:has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买