您的前端发出了CORS请求,以查看
HTTP Verbs您支持的方法()是什么。这通常是货币操作所必需的,例如
POST或
PUT用于修改数据。
因此,您的前端将首先进行此调用,而后端需要使用允许的方法进行响应,您还可以限制特定的URI,然后在成功验证后进行目标调用。
这是完全正常的,角度在内部执行此操作,以便在不知道服务器是否允许的情况下不会发出不必要的数据请求。
这是您将在中进行设置的方法
Spring。
//Change/Customize as necessary @Bean CorsConfigurationSource corsConfigurationSource() { UrlbasedCorsConfigurationSource source = new UrlbasedCorsConfigurationSource(); CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedOrigin("<your origin>"); corsConfiguration.setAllowedMethods(Arrays.asList( HttpMethod.GET.name(), HttpMethod.HEAD.name(), HttpMethod.POST.name(), HttpMethod.PUT.name(), HttpMethod.DELETE.name())); corsConfiguration.setMaxAge(1800L); source.registerCorsConfiguration("/**", corsConfiguration); // you restrict your path here return source; }如果您还在
response headers后端使用任何自定义,则还需要在CORS配置中允许它。举个例子
corsConfiguration.addAllowedHeader("*"); corsConfiguration.addExposedHeader("header1"); corsConfiguration.addExposedHeader("header2");


