My Ionic app is not sending the Headers. Here is my Code.
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);
});
}
So what am I missing? When I do headers1.get('Authorization') I get the Token I want. Everything works fine in Postman.
Just do it like that it works finr
this.http.post("YOUR URL", "PARAMETER", { headers: { Auth: token } });
When i try to import RequestOptions it says they are not available in /angular/common/https.
Add HttpHeaders() instead of headers
Than it gives me that error: No overload matches this call. The last overload gave the following error. Argument of type 'HttpHeaders' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
just do it like that this.http.post("Your url", "Your params", { headers: { Auth: token } });
thank you that worked