I created an api with authorization, It is working correctly in postman but but i am not able to use authorization in flutter, I am getting Statuscode: 401(unauthorized) in flutter but in postman i am getting statuscode: 200(success). Here is my Code:

sharedPreferences = await SharedPreferences.getInstance();
    String Authorization =  sharedPreferences.getString("token"); 
    var data = await http.get("http://10.148.7.58/Election/api/TblDatas",
        headers: <String, String>{'Authorization': '$Authorization',}
    );

 //Also tried these
    //headers: {'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': '$Authorization',}
    //headers: {HttpHeaders.contentTypeHeader: "application/json", HttpHeaders.authorizationHeader: "$Authorization"}

    print('status code is' + (data.statusCode).toString());


Solution 1: hasan karaman

headers: <String, String>{
'Content-Type': 'application/json', //add context-type
'Accept': 'application/json',//add accept
'Authorization': 'Bearer $token',
}


Solution 2: Mani

Make sure that your server accepts lower case header names - in this case authorization, as Dart will lower case them. This fools some servers that aren't RFC compliant