Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dart flutter httpclient : authorization

Tags:

jwt

flutter

dart

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

like image 550
David Avatar asked Dec 11 '17 23:12

David


1 Answers

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});
like image 136
Ridha Rezzag Avatar answered Sep 24 '22 10:09

Ridha Rezzag