Flutter status code 403 yet the authorization is correct
03:10 02 Nov 2024

I'm trying to run a flutter htttp function, which runs and sends a json response correctly on postman while using the same bearer token, but when run in my flutter code, it returns header options instead of a json response from the server.

Below is the function I'm trying to run:

Future signIn() async {
  Map body = {
    "email": emailcontroller.text,
    "password": passwordcontroller.text,
  };

  try {
    setState(() {
      isLoading = true;
    });
    Map head = {
      "Authorization": "Bearer  ZjdkMjZhNTJmMzZkNTYwNzI0YTE5MGUwODVjM2UwMjI=",
    };

    var url = Uri.parse(
        'https://staging.mam-laka.com/api/?resource=user&action=login');
    var responsee = await http.post(url, headers: head, body: jsonEncode(body));

    print("Status code: ${responsee.statusCode}");
    print("Response headers: ${responsee.headers}");
    print("Response body: ${responsee.body}");

    Map data = jsonDecode(responsee.body);
    print(data);
  } catch (e) {
    print("Error: $e");
  } finally {
    setState(() {
      isLoading = false;
    });
  }
}

And below is the response that I'm getting:

flutter: Status code: 403
flutter: Response headers: {connection: keep-alive, access-control-allow-origin: *, transfer-encoding: chunked, date: Sat, 02 Nov 2024 08:08:22 GMT, content-encoding: gzip, server-timing: cfL4;desc="?proto=TCP&rtt=174408&sent=4&recv=7&lost=0&retrans=0&sent_bytes=2814&recv_bytes=658&delivery_rate=11287&cwnd=250&unsent_bytes=0&cid=ec74b12a68b946f8&ts=488&x=0", 
cf-cache-status: DYNAMIC, 
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=WKSXtShxltV1X3mhbHNvFbBrmMaUkgbKcWZcMpIPWUlet%2Bg%2BA0HpEmQKv56BgeNqFxhEVb%2FCbkZZHei4CFaSVW3ojQwqdIFf0NTHGYjJRufpZyD7PhskNlPzML3TiVhBrDRcBSNE6g%3D%3D"}],"group":"cf-nel","max_age":604800}, 
access-control-max-age: 3600, 
content-type: application/json; charset=UTF-8, 
server: cloudflare, 
access-control-allow-headers: Content-Type, 
Access-Control-Allow-Headers, 
Authorization, 
X-Requested-With, 
alt-svc: h3=":443"; ma=86400, 
access-control-allow-methods: POST, 
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}, 
cf-ray: 8dc2a2e1de660b5c-AMS}
flutter http cors