我正在尝试使用Angular 5实现登录功能。每次我都在浏览器控制台上收到HTTP POST请求的 net :: ERR_CONNECTION_TIMED_OUT 。
authentication.service.ts中的服务功能
login(username: string, password: string) {
let url = environment.baseUrl + '/v1/agent/' + username + '/login';
return this.http.post<any>(url, { "password": password, "user_name": username })
.pipe(map(user => {
// login successful if there's a jwt token in the response
if (user && user.token) {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('dmc_currentUser', JSON.stringify(user));
}
console.log(user);
return user;
}));
}
login.component.ts中的登录功能
onLoggedin() {
this.loginBtnDisabled = true;
this.submitted = true;
if (this.loginForm.invalid) {
this.loginBtnDisabled = false;
return;
}
this.loading = true;
localStorage.setItem('isLoggedin', 'true');
this.authenticationService.login(this.f.userName.value, btoa(this.f.password.value))
.pipe(first())
.subscribe(
data => {
console.log(data.headers.get('access_token'));
console.log(data.headers.get('refresh_token'));
console.log(data.headers.get('session_state'));
this.router.navigate(['/dashboard/dashboard1']);
},
error => {
this.loading = false;
this.loginFailed = true;
this.loginBtnDisabled = false;
});
}
我也附上我的 SWAGGER API文档的屏幕截图。
已更新:
邮递员的回复-我不确定我是不是正在按照正确的方式进行操作。