net :: ERR_CONNECTION_TIMED_OUT用于HTTP POST请求

时间:2019-11-02 15:17:46

标签: angular typescript http rxjs observable

我正在尝试使用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文档的屏幕截图。

enter image description here

  1. 有人可以在这里帮助我解决此问题吗?
  2. 在什么情况下我们 出现 net :: ERR_CONNECTION_TIMED_OUT 错误?
  3. 此格式对于HTTP调用中的基本URL正确吗-> http://XXX.XX.XX.XXX:8081

已更新:

邮递员的回复-我不确定我是不是正在按照正确的方式进行操作。

enter image description here

0 个答案:

没有答案