【发布时间】:2016-02-13 20:53:29
【问题描述】:
我想实现身份验证。实际上,我的项目是在 Angular 2 Beta 中构建的,但我使用this 身份验证示例进行测试。我有自己的 API,只是将它的 url 添加到这个示例项目中。它不起作用)它显示了这个错误:
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
这里是登录方法:
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);
});
}
【问题讨论】:
标签: angular