温馨提示:本文翻译自stackoverflow.com,查看原文请点击:typescript - Headers are not sending Ionic
ionic-framework typescript

typescript - 标头未发送Ionic

发布于 2020-04-10 17:54:33

我的Ionic应用程序未发送标题。这是我的代码。

async setAnzahlTische() {
let headers1 = new Headers();
headers1.append('Accept', 'application/json');
headers1.append('Content-Type', 'application/json' ); 
headers1.set('Authorization', await this.storage.get('token'));
headers1.append('Access-Control-Allow-Origin', '*');
headers1.append('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
headers1.append('x-Trigger', 'CORS');

let tischid = 2;


let postData =  {

    'tischid' : tischid

  };
let tos = JSON.stringify(postData);

this.http.post('http://127.0.0.1:8000/updatedata', tos, {responseType: 'text'})
    .subscribe(data => {
        console.log(data);
        //this.router.navigate(['/home']);

    }, error => {
        console.log(error.message);
    });
}

那我想念什么呢?当执行headers1.get('Authorization')时,我得到了想要的令牌。 Postman 一切正常。

查看更多

提问者
rotschopf
被浏览
91
Jain Bhavesh 2020-02-03 00:10

那样做就可以了

 this.http.post("YOUR URL", "PARAMETER", { headers: { Auth: token } });