Hello,
its me… I dont find any solution for my Problem. I dont get my Bearer Token in variable.
here is my header and my script ![
Header:
Script:
Can anyone help me pls. How can i get this Bearer Token and can save it in Localstorage. Any solutions?
bilow
January 7, 2019, 9:06am
2
You can try 2 methods.
When creating the headers, create it with all the necessary items:
let headers: HttpHeaders = new HttpHeaders({
"Content-Type": "application/json",
"Content-Type": "application/x-ww-form-urlencoded",
"Access-Control-Allow_Origin": "*",
"Access-Control-Allow_Origin": "POST, GET, OPTIONS",
});
When appending a new header, or doing any kind of edit, you have to assign it to ‘xxx’ (e.g. itself).
let headers: HttpHeaders = new HttpHeaders({ "Content-Type": "application/json" });
headers = headers.append("Content-Type": "application/x-ww-form-urlencoded");
headers = headers.append("Access-Control-Allow_Origin": "*");
headers = headers.append("Access-Control-Allow_Methods": "POST, GET, OPTIONS");
But i do this in my code to with headers.append??
bilow
January 7, 2019, 9:10am
4
No you do:
headers.append(“Content-Type”: “application/x-ww-form-urlencoded”);
you have to do:
headers = headers.append(“Content-Type”: “application/x-ww-form-urlencoded”);
Okay i add this to my code. But how can i store my Bearer Token I really dont know…
bilow
January 8, 2019, 9:37am
6
What do you mean with ‘store Bearer token’?
I mean this. after the Word: Bearer
I want to store this token in LocalStorage. (eyJ0eXAi…)
bilow
January 8, 2019, 10:04am
8
First of all: Read the docs : https://ionicframework.com/docs/
Watch some videos: https://www.youtube.com/watch?v=O2WiI9QrS5s
You’ll have to understand what you’re working with first. Then you can go on with trying to understand and learn the ‘thing’ you are working with.
After understanding what you’re doing, go read more in depth for more information about for example the (Angular) HttpHeaders: https://angular.io/api/common/http/HttpHeaders (You answer is in here… : ))
Good luck!
code in your server
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
?>