Ionic 3将标题中的jwt_token传递给laravel app

时间:2018-04-23 23:11:09

标签: angular laravel typescript ionic3 jwt

我试图发送一个get to url传递一个jwt令牌,到目前为止我已经得到了这个: 服务器是在laravel上构建的,并且与邮递员在标头上传递令牌完美配合,但不像下面的代码那样进行,

import { Http } from '@angular/http';
import { Storage } from '@ionic/storage';
import { HTTP } from '@ionic-native/http';
import { HttpClient } from '@angular/common/http';

constructor(
    public http: HttpClient,
    public httpnative: Http,
    private storage: Storage
  )



PostToApi(endpoint:any, body:any, headers:any){
  return this.http.post(this.apiurl+endpoint, body, headers);
}
PostData(){
this.storage.get('jwt_token').then(token=>{
 let body = new FormData();
 body.append('data_nasc', '07-04-1991');

 let headers = new Headers();
 headers.append('Content-Type', 'application/x-www-form-urlencoded');
 headers.append('Accept', 'application/json');
 headers.append('Authorization', 'Bearer ' + token);

 this.webservices.PostToApi('/cliente/perfil',body,headers).subscribe(
  data => {
    let dados:any;
    dados = data;
    let retorno: any;
    retorno = JSON.parse(dados._body);
    console.log(JSON.stringify(retorno));
  },
  error => {
    console.log(error._body);
  },
  () => {
  }
);
});
}

当我发送此数据时,我在console.log上收到了一个token_not_provided错误._

PS。我愿意为此付出解决方案

0 个答案:

没有答案