http调用响应头在角度2中返回null

时间:2016-11-18 06:36:50

标签: angular ionic2

IOnic服务案例 当我运行 ionic serve http调用时,在响应头中返回null。我需要在每次下一次调用时发送标头以进行安全身份验证。但是当我呼叫登录http呼叫时,Api在响应头中返回null。

离子运行android案例  但另一种情况是,当我运行离子运行android 时,它会在登录呼叫中给我响应头,但是当我调用下一个http调用后,它立即在下一次调用的响应头中返回null。

这是我的登录代码:

 Login(email, password) {

        let body = JSON.stringify({email: email, password: password});
        //HTTP POST CALL FOR LOGIN 
        return this.http.post(this.LOGIN_URL, body, {headers: this.contentHeader}).subscribe(response => {

            if (response) {

                console.log('in login if');
                console.log(response.headers.get('uid'));
                console.log(response.headers.get('client'));
                console.log(response.headers.get('access-token'));

          this.uid = response.headers.get('uid');
          this.client =  response.headers.get('client');
          this.access_token =  response.headers.get('access-token');

//saving header for next call
  Save_Header(this.access_token, this.client, this.uid );


            } else{
              // login failed
              console.log("coming in........");
              this.error = 'Something went wrong';
              //  this.loading = false;
            }
    }

以下是为下次通话保存标题的功能:

Save_Header(access_token,client, uid){
        this.contentHeader.append('access-token', access_token);
        this.contentHeader.append('client', client);
        this.contentHeader.append('uid', uid);
       //console.log(this.contentHeader);
    }

获取下一个电话标头的功能:

   Get_Header(){
    return this.contentHeader;
}

下一个http来电:

Get_All_Delivered_orders(){
        console.log("in userservice all delivered orders")
        console.log(this.Get_Header());
       return this.http.get(URL,{headers: this.Get_Header()});// getting saved headers
    }

在实施或Api中会出现什么问题? 请指导谢谢!

0 个答案:

没有答案