Reputation: 77
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?
Upvotes: 6
Views: 1025
Reputation: 89956
If you already know the encoded URL, just use Uri.parse
:
var uri = Uri.parse('http://some.domain/json.php?key=%DF');
Uri.parse
is far simpler and far less error-prone than attempting to use Uri.http
/Uri.https
directly. Avoid using those, and complain to anyone who instructed you to use them.
Upvotes: 0
Reputation: 96
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)}'
);
Upvotes: 5