'Flutter - Server Not Seeing UserAgent in Get Request

I am sending get requests in a flutter app and my server is sending a response depending on data from the phones user agent, when i send a request from a native app there is no problem -

example: "Dalvik/2.1.0 (Linux; U; Android 10; Infinix X655C Build/QP1A.190711.020)"

but when i do the same from my flutter app on an android phone the sever sees something else. example: "Dart/2.16 (dart:io)"

this is happening even though the get request has the headers property in the request

this is the flutter code:

     Future<bool> approvedData() async {
   var serverUrl = "https://appsofksenia.com/app_data";
   String userAgent = await FlutterUserAgent.getPropertyAsync('userAgent');
   Map<String, String> headers = {
     HttpHeaders.authorizationHeader: 'Basic $userAgent',
     'Content-Type': 'application/json; charset=UTF-8',
     'Accept': 'application/json',
     "User-Agent": userAgent,
   };
   http.Response res = await http.get(Uri.parse(serverUrl),headers: headers);
   if(res.statusCode == 200){
     if(res.body.isNotEmpty) {
       dynamic response = json.decode(res.body);
       var serverResponse = PrivacyResponse.fromJson(response);
       var serverAnswer = serverResponse.privacy;
       if (serverAnswer == "data_change") {
         return true;
       } else {
         return false;
       }
     }else{
       return false;
     }
   }else{
     return false;
   }
}

debug of the flutter app



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source