Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart character encoding in http request

Just learning Flutter and running into this issue when trying to call an API:

final response = await http.get(
  Uri.https(apiBaseUrl, apiBaseEndpoint + "/tasks"),
  headers: {
    "Authorization": "Bearer " + apiKey,
  },
);

print(response.body);

Part of my response contains İftar and it's supposed to be İftar. I imagine it's some encoding problem? curl gives me back the response with the proper characters.

Basically: is this a text encoding problem? If so, how do I fix my request?

like image 934
derekantrican Avatar asked Jul 10 '26 16:07

derekantrican


1 Answers

Ok, after a little bit more digging on the http docs I realized it wasn't in how I made my request that needed to change, but how I handled the response. I was doing

final decodedJson = json.decode(response.body);

and I should've been doing:

final decodedJson = json.decode(utf8.decode(response.bodyBytes));

That has solved my issue!

like image 198
derekantrican Avatar answered Jul 13 '26 18:07

derekantrican



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!