为什么每个API请求都会创建一个新会话?

时间:2018-05-30 07:00:22

标签: angular angular2-http

我正在将我的项目从AngularJS移动到Angular,它正在为每个请求创建一个不同的会话;为什么?我使用了withCredentials,这是user.service.ts

loginUser(username,password) {
    var params = "emailId="+username + "&password="+ password;
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    let options = new RequestOptions({ headers: headers, withCredentials: true });
    return this.authHttp.post(this.baseUrl+'authenticate/login?'+params, options)
    .map((response: Response) => response.json())
    .catch(this.handleError);
  }

getUserDetails() {
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    let options = new RequestOptions({ headers: headers, withCredentials: true });
    return this.authHttp.get(this.baseUrl+'user/getUserDetails', options)
    .map((response: Response) => response.json())
    .catch(this.handleError);
  }

这是我的组成部分:

this.userService.loginUser(email,password).subscribe(
        data => {
          if(data.hasOwnProperty('status')) {
            if(data.status != null && data.status != "") {
              if(data.status.toLowerCase() == 'active') {
                $(".login_btn + .sign-btn").css("display","block");
                $(".resend-error").html("");
                this.activationMsg = "";
                this.userService.getUserDetails().subscribe(
                data => {
                  console.log(data);
                },error => {

                });

              }
            }
          }
       });

0 个答案:

没有答案