CORS preflight request fails due to a standard header

前端 未结 7 1132
灰色年华
灰色年华 2020-12-23 17:04

While debugging a CORS issue I am experiencing I\'ve found the following behaviour. Chrome makes the following OPTIONS preflight request (rewritten in CURL by Chrome itself)

7条回答
  •  离开以前
    2020-12-23 17:41

    i also faced the same issue and find solution for enabling global cors issue in spring boot

    @Configuration
    @EnableWebMvc
    public class WebConfig extends WebMvcConfigurerAdapter {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").allowedMethods("GET", "POST", "PUT", "DELETE").allowedOrigins("*")
                    .allowedHeaders("*");
        }
    }
    

    after this , we need to enable CORS in spring security level also, so for this add cors() in your SecurityConfiguration class which extent WebSecurityConfigurerAdapter

     @Override
        protected void configure(HttpSecurity httpSecurity) throws Exception {
    
            httpSecurity
                    .cors()
                    .and()
                    .csrf().disable()
                    .authorizeRequests()..
    
        }
    

提交回复
热议问题