urlencoding in Dart

Sudar picture Sudar · Apr 20, 2012 · Viewed 29.5k times · Source

Is there a function to do urlencoding in Dart? I am doing a AJAX call using XMLHttpRequest object and I need the url to be url encoded.

I did a search on dartlang.org, but it didn't turn up any results.

Answer

gines capote picture gines capote · Jul 1, 2013
var uri = 'http://example.org/api?foo=some message';
var encoded = Uri.encodeFull(uri);
assert(encoded == 'http://example.org/api?foo=some%20message');

var decoded = Uri.decodeFull(encoded);
assert(uri == decoded);

http://www.dartlang.org/docs/dart-up-and-running/contents/ch03.html#ch03-uri