0
this Spring tutorial次のBeanを設定ロジックに追加しました。私はSpring Bootを使用しています。Angular AppとSpringバックエンド間のCORS半作業
あなたは春のブートを使用している場合、ちょうど、次のようWebMvcConfigurer Beanを宣言することをお勧めします。
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
// Just slightly modified
.allowedMethods("HEAD", "GET", "PUT", "POST",
"DELETE", "PATCH", "OPTIONS")
.allowedOrigins("*")
.allowedHeaders("*");
}
};
}
は、ここでのことだ:私はクライアント側からユーザーを登録することができています:
onSubmit() {
this.http.post('http://localhost:8080/register', this.registerForm.value)
.subscribe(
data => this.onRegisterSuccess(),
err => alert(err.error.message)
);
}
が、私は私のOAuth2トークンのためのエンドポイントにアクセスすることはできません。
onSubmit() {
const headers = new HttpHeaders()
.set('Content-Type', 'application/x-www-form-urlencoded')
.set('Authorization', 'Basic dGVzdGp3dGNsaWVudGlkOlhZN2ttem9OemwxMDA=');
this.http.post('http://localhost:8080/oauth/token', this.loginForm.value, {headers: headers})
.subscribe(
data => this.onLoginSuccess(),
err => alert(err.error.message)
);
}
た会話:
私は問題が何であるか見当がつかない。