zoukankan      html  css  js  c++  java
  • springboot 跨域

    参考:

    https://blog.csdn.net/qq779446849/article/details/53102925

    https://blog.csdn.net/wo541075754/article/details/50696841

    springboot启动类中添加2个方法:

        private CorsConfiguration buildConfig() {  
            CorsConfiguration corsConfiguration = new CorsConfiguration();
            // 允许跨域访问的域名
            corsConfiguration.addAllowedOrigin("*");// 请求头
            corsConfiguration.addAllowedHeader("*");  
            // 请求方法 HttpMethod.DELETE/POST/GET/PUT/DELETE/OPTIONS
            corsConfiguration.addAllowedMethod("*");  
            // 预检请求的有效期,单位为秒。
            corsConfiguration.setMaxAge(3600L);
            
            return corsConfiguration;  
        }  
          
        /** 
         * 跨域过滤器 
         * @return 
         */  
        @Bean  
        public CorsFilter corsFilter() {  
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();  
            source.registerCorsConfiguration("/**", buildConfig()); // 4  
            return new CorsFilter(source);  
        }

    跨域安全问题:https://www.cnblogs.com/cloudshare/p/7192646.html

  • 相关阅读:
    8.8总结
    8.4总结
    8.3总结
    题目分享H 二代目
    题目分享G 二代目
    题目分享E 二代目
    题目分享F 二代目
    题目分享D 二代目
    题目分享C 二代目
    题目分享Y
  • 原文地址:https://www.cnblogs.com/lvlin241/p/8760914.html
Copyright © 2011-2022 走看看