我使用Angular 2和Spring Security创建了登录应用程序。在这里,我使用Angular2创建登录页面并保存在app文件夹中。当我点击按钮提交表单时,它将调用login.componet.ts文件中定义的getLogin()方法。我在这里叫服务。但我得到状态代码0.如下 EXCEPTION:响应状态:URL为0:null main.bundle.js:545Response,状态:0表示URL:null
<form id="login-form" class="login-form" (submit)="login()" method="POST">
<input type="text" name="username" id="email"placeholder="Email Address" [(ngModel)]="username">
<input type="password" name="password" id="password" placeholder="Password" [(ngModel)]="password">
<a href="#">Forgot your password?</a>
<button class="btn" type="submit" value="">SIGN IN</button>
</form>
Login.component.ts
login():void {
console.log("Username :"+this.username+" Password :"+this.password);
this.service.getLogin(this.username,this.password).subscribe(lst console.log(lst));
}"
服务:
getLogin(username,password):Observable<string> {
let body = new URLSearchParams();
body.set('username', username);
body.set('password', password);
let response = this.http.post(`${AppSettings.BACK_ENDPOINT}/login`,body);
console.log("=======LoginService=======");
return response.map(isAuthenticated);
}
}
function isAuthenticated(response:Response):string {
return response.json();
}
When client logged in successfully then Spring Security returning defaultSeccessURl and should redirect to that default success url.
but its not happening when calling by calling above service
Please help me.