i would like to perform a basic authentication with a simple token; how to perform this in flutter? which is the best way?
var response = await httpClient.post(url,
body: {'name': 'doodle', 'color': 'blue'});
is it sufficient to ad an authentication header, for example in this way ?
var response = await httpClient.post(
url,
header:{
'authorization' : 'bearer $token',
'content-type':'application/json'
},
body :{some body});
I'm using a JWT token type
Pay attention to the word Bearer its must be Capitalized other ways it wont work, not sure whats the reason, but for flutter http calls make sure to capitalize that word like this
var response = await httpClient.post(
url,
headers:{
"Accept": "application/json",
"Content-type": "application/json",
"Authorization": "Bearer $token"
},
body :{some body});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With