URI中的一些特殊字符:/, :, &, #,不用转义。
在dart中,encodeFull() 和 decodeFull():
var uri = 'http://www.flydean.com/doc?title=dart uri';
var encoded = Uri.encodeFull(uri);
assert(encoded ==
'http://www.flydean.com/doc?title=dart%20uri');
var decoded = Uri.decodeFull(encoded);
assert(uri == decoded);
编码所有的字符,包括:/, :, &, #,使用encodeComponent() 和 decodeComponent():
var uri = 'http://www.flydean.com/doc?title=dart uri';
var encoded = Uri.encodeComponent(uri);
assert(encoded ==
'http%3A%2F%2www.flydean.com%2Fdoc%3Ftitle%3Ddart%20uri');
var decoded = Uri.decodeComponent(encoded);
assert(uri == decoded);
字符串生成Uri ,解析URI
URI是由scheme,host,path,fragment组成的:
var uri =
Uri.parse('http://www.flydean.com/doc#dart');
assert(uri.scheme == 'http');
assert(uri.host == 'www.flydean.com');
assert(uri.path == '/doc');
assert(uri.fragment == 'dart');
assert(uri.origin == 'http://www.flydean.com');
Uri的构造函数:
var uri = Uri(
scheme: 'http',
host: 'www.flydean.com',
path: '/doc',
fragment: 'dart');
assert(
uri.toString() == 'http://www.flydean.com/doc#dart');