...has been blocked by CORS policy: Response to preflight request doesn‘t pass access control check

Access to XMLHttpRequest at 'http://localhost:88/api/sys/login' from origin 'http://localhost:8001' 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.
xhr.js?ec6c:178 POST http://localhost:88/api/sys/login net::ERR_FAILED

解决办法:
在网关配置文件中加入跨域配置:

    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();

        //1.配置跨域
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.setAllowCredentials(true);

        source.registerCorsConfiguration("/**",corsConfiguration);
        return new CorsWebFilter(source);
    }

注意:

corsConfiguration.addAllowedHeader("*");

即可。
如果做到这一步还是有问题,那么就需要将cookie权限设置

在这里插入图片描述

要允许访问前端url
在这里插入图片描述


版权声明:本文为Austin_原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。