Моя страница входа столкнулась с проблемой:
Access to XMLHttpRequest at 'https://___.app/login' from origin
'http://localhost:8100' has been blocked by CORS policy:
Request header field access-control-allow-origin is not
allowed by Access-Control-Allow-Headers in preflight response.
У меня есть Access-Control-Allow-Origin: *
Но это не помогло устранить ошибку. Как исправить?
login() {
var url = 'https://____.app/login';
var postData = JSON.stringify({
// saving it as Email and will be used at server.js
Email: this.loginForm.value['email'],
Password: this.loginForm.value['password'],
});
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-AllowMethods': 'GET,HEAD,PUT,PATCH,POST,DELETE'
})
};
this.http.post(url, postData, httpOptions).subscribe((data) => {
console.log('postData:', postData)
if (data == false) {
this.loginfail()
}
else if (data == true) {
this.loginsuccess()
this.modalController.dismiss();
}
}, error => {
console.log(error);
});
}