Ionic3 API身份验证

时间:2018-05-12 13:35:51

标签: api authentication ionic3

AuthService

loginCheckUri: string = 'http://127.0.0.1:8000/api/login_check';
login(username:string,password:string) {

    let headers = new Headers();
    headers.append('content-type', 'application/x-www-form-urlencoded');
    let body = new URLSearchParams();
    body.set('username', username);
    body.set('password', password);
    return new Promise((resolve, reject) => {
      this.http.post(this.loginCheckUri, body, { headers: headers }).subscribe(res => {
        resolve(res.json());
        console.log('success');
      }, (err) => {
        reject(err);
        console.log('error: ',err);
      });
    })
  }

LoginPage.ts

signIn() {
      this.authProvider.login(this.user.email,this.user.password)
      .then((res) => { this.navCtrl.push(HomePage); })
      .catch((err)=>{console.log('error');});
  }
  

我成功回复,状态代码:200 以及令牌但是    我在控制台出错了,

响应

Response screenshot

控制台错误

Console Error screenshot

0 个答案:

没有答案