存储然后发送 API 响应

Store then Send API response

因此,登录后,API 会回答三个参数:姓名、电子邮件和令牌。为了验证用户订阅的课程,我必须传递 (post) 2 个参数,token 和 course,所以 API 回答用户订阅了哪些课程。我在 login.ts 页面中以这种方式存储令牌:

userLogin(){
    this.authloginService.logarConta(this.email, this.password).then((result)=>{

      localStorage.setItem('token', result['token'])
      console.log(result['token']);
      this.navCtrl.navigateForward('inicio')

     });

service.ts 页数:

logarConta(email: string, password:string){

      email = encodeURIComponent(email);
      password = encodeURIComponent(password);

      var data = `email=${email}&password=${password}`;

    return this.http.post('https://api.elainneourives.com.br/api/login', data, {headers: this.headers}).toPromise();

  }

如何发送令牌变量来验证课程?

API获取课程的服务请求:

getCourses(token:string, course:string){

    token = encodeURIComponent (token);
    course = encodeURIComponent (course);

      var cursos = `token=${token}&course=${course}`;

      return this.http.post('https://myapi.com/api/subscriptions', cursos , {headers: this.headers}).toPromise();

  }
token = encodeURIComponent (localStorage.getItem('token'));

像这样就可以访问了