CORS preflight request fails due to a standard header

前端 未结 7 1165
灰色年华
灰色年华 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 18:00

    I had the same issue. I've resolve it by adding 'OPTIONS' to allowed CORS methods in my Spring MVC configuration.

    @Configuration
    @EnableWebMvc
    @ComponentScan
    public class RestApiServletConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            super.addCorsMappings(registry);
            registry.addMapping("/**")
                    .allowedOrigins("http://localhost:3000", "http://localhost:8080")
                    .allowedMethods("GET", "PUT", "POST", "DELETE", "OPTIONS");
        }
    }
    

提交回复
热议问题