Dart/Flutter: URI/HTTPClient - disable automatic escaping of %
The queryParameters
parameter of the Uri.http
constructor expects an unencoded map of data that it encodes using it's own standard, since you need to use another standard for this case might be better to use the Uri
constructor and build your own query string and pass to the query
parameter.
Something like this should do the trick:
final uri = Uri(
scheme: 'http',
host: 'some.domain',
path: 'json.php',
query: 'key=${Uri.encodeQueryComponent('ß', encoding: latin1)}'
);
Bridystone
Updated on December 29, 2022Comments
-
Bridystone over 1 year
I have a problem with the dart/flutter URI implementation. % is automatically replaced by %25.
i want to access the following URL:
http://some.domain/json.php?key=%DF
[%DF=ß in ASCII/latin1]the code:
final uri = Uri.http('some.domain', 'json.php', {'key': 'ß'});
results in
http://some.domain/json.php?key=%C3%9F
[ß in UTF-8]when trying
final uri = Uri.http('some.domain', 'json.php', {'key': '%DF'});
it results in:
http://some.domain/json.php?key=%25DF
[% automatically escaped to %25]when trying explicit encoding:
final uri = Uri.http('some.domain', 'json.php', {'key': Uri.encodeQueryComponent('ß', encoding: latin1)});
it results in:
http://some.domain/json.php?key=%25DF
[% automatically escaped to %25]How can I disable the automatic encoding of % to %25?!
any ideas?
-
Bridystone almost 3 yearsYES YES YES! :) Thanks very much for this fast support - IT WORKS. I debugged 2 hours with a short deep dive into the dart core code, to see that there is enforced encoding in
queryParameters
that this circumvents the issue is great!