CORSフィルタをSpringブートWebアプリケーションに追加する必要があります。私は私のAPIにアクセスしようとしている私は、次のエラーを受信したときに今SpringブートCORSフィルタ - CORSプリフライトチャネルが成功しませんでした
@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
// @formatter:off
registry
.addMapping("/**")
.allowedOrigins(CrossOrigin.DEFAULT_ORIGINS)
.allowedHeaders(CrossOrigin.DEFAULT_ALLOWED_HEADERS)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.maxAge(3600L);
// @formatter:on
}
...
}
:以下の文書で説明するように
私はこれが私のconfigですhttp://docs.spring.io/spring/docs/current/spring-framework-reference/html/cors.html
CORSのマッピングを追加した
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://example.com/api/v1.0/user. (Reason: CORS preflight channel did not succeed).
これはFFコンソールからのスクリーンショットである。
この問題を回避するために、私は間違っていますか、CORSヘッダーを正しく設定する方法を教えてください。
適切なRESTful APIをサポートしたい場合は、そこにPUT動詞も追加すべきでしょうか? –