How to alter allowed headers in Spring Boot

前端 未结 3 2064
南笙
南笙 2021-01-22 23:58

I\'m currently using Auth0 (and an Angular 2 GUI), which sends a header of the type \"x-xsrf-token\" in the request to a Spring Boot API.

I get the error:

3条回答
  •  没有蜡笔的小新
    2021-01-23 00:23

    try,

    @Bean
        public FilterRegistrationBean corsFilter() {
            UrlBasedCorsConfigurationSource source = new     UrlBasedCorsConfigurationSource();
            CorsConfiguration config = new CorsConfiguration();
            config.setAllowCredentials(true);
            config.addAllowedOrigin("*");
    
            config.addAllowedHeader("*");       
            config.addAllowedMethod("*");        
            source.registerCorsConfiguration("/**", config);
    
    
    
            FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
            bean.setOrder(0);
            return bean;
    
    
        }
    

    https://spring.io/blog/2015/06/08/cors-support-in-spring-framework

提交回复
热议问题