what is the correct way to pass Bearer token in header section of my HTTP.Post in flutter

Advertisements

My Post API need a customer_id in body but also need a bearer token. I am passing it using following code

var myId="1005",
var token="my Token here"
var response = await http.post(Uri.parse("http://haulers.tech/jashn/mobile/home/shoutouttype"),
body: ({
"customer_id":myId.toString,
}),
headers: ({
"Authorisation": token.toString, //here I want to pass Bearer Token
})
);
This code return status code 401.

>Solution :

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});

Leave a ReplyCancel reply