I want to implement authentication. Actually, my project is being built in Angular 2 Beta, but I'm using this authentication sample for testing purposes. I have own API, and just added its url to this sample project. It didn't work) It shows this error:
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
Fetch API cannot load http://blah-blah-blah. Response for preflight has invalid HTTP status code 405
Here is the login method:
login(event, phone, password) {
event.preventDefault();
window.fetch('http://blah-blah-blah', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
phone, password
})
})
.then(status)
.then(json)
.then((response:any) => {
localStorage.setItem('access_token', response.id_token);
this.router.parent.navigateByUrl('/home');
})
.catch((error) => {
alert(error.message);
console.log(error.message);
});
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…