zoukankan      html  css  js  c++  java
  • springboot2和vue项目不依靠网关等手段,解决跨域,cookie跨域

    https://blog.csdn.net/a704397849/article/details/103820538

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.cors.CorsConfiguration;
    import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
    import org.springframework.web.filter.CorsFilter;
    
    /**
     * @author:
     * @create: 
     **/
    @Configuration
    public class CorsConfig {
        private CorsConfiguration buildConfig() {
            CorsConfiguration corsConfiguration = new CorsConfiguration();
            corsConfiguration.addAllowedOrigin("*"); // 1允许任何域名使用
            corsConfiguration.addAllowedHeader("*"); // 2允许任何头
            corsConfiguration.addAllowedMethod("*"); // 3允许任何方法(post、get等)
            corsConfiguration.setAllowCredentials(true);//支持安全证书。跨域携带cookie需要配置这个
            corsConfiguration.setMaxAge(3600L);//预检请求的有效期,单位为秒。设置maxage,可以避免每次都发出预检请求
            return corsConfiguration;
        }
    
        @Bean
        public CorsFilter corsFilter() {
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            source.registerCorsConfiguration("/**", buildConfig()); // 4
            return new CorsFilter(source);
        }
    }
  • 相关阅读:
    spring cloud教程
    ideaaaaaaaaa
    Django
    Django 基础介绍
    Pychram
    python
    python
    python
    Python
    Python -- Scrapy 命令行工具(command line tools)
  • 原文地址:https://www.cnblogs.com/a1304908180/p/12737460.html
Copyright © 2011-2022 走看看