这是我在角度2中的第一个应用程序,我正在为我的移动应用程序进行jwt身份验证,我有HTTP帖子的问题,我已经检查了我的帖子Url in Postman它工作正常,我也得到了令牌。但是当我从客户端发布时,我收到了一个错误。请让我出去。
login.html
<form (ngSubmit)="login()" #loginForm="ngForm">
<ion-list>
<ion-item class="email_border">
<ion-label class="labelstyle"> <ion-icon class="icon" color="dark" ios="ios-person" md="md-person"></ion-icon></ion-label>
<ion-input type="text" placeholder="Email" name="name" [(ngModel)]="name" required></ion-input>
</ion-item>
<div style="font-size:0;height:6px;"></div>
<ion-item class="email_border">
<ion-label class="labelstyle"> <ion-icon class="icon" color="dark" ios="ios-unlock" md="md-unlock"></ion-icon></ion-label>
<ion-input type="password" placeholder="Password" name="Kennwort" [(ngModel)]="Kennwort" required></ion-input>
</ion-item>
</ion-list>
<button icon-left ion-button block type="submit" class="log" [disabled]="!loginForm.form.valid">
<ion-icon style="font-size: 30px" ios="ios-key" md="md-key"></ion-icon> Login </button>
</form>
<button ion-button block clear (click)="register()" class="register"> Register For Free Trail </button>
<button ion-button block clear (click)="resetPwd()" class="fpasswd"> Forgot Password </button>
login.ts
login(name,Kennwort) {
this.auth.loginuser(name,Kennwort).subscribe((result) => {
if (result) {
this.navCtrl.setRoot(HomePage);
}
});
}
authservice.ts
loginuser(name:string, Kennwort:string):Observable<boolean> {
var headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post('node.futures-services.com:9000/api/authenticate/', JSON.stringify({ name:name, Kennwort:Kennwort }), { headers:headers })
.map(res => res.json()).map((res) => {
if (res.success) {
localStorage.setItem('token', res.token);
this.loggedIn = true;
}
return res.success;
}).catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}
错误看起来像error