打印内容:
import 'dart:convert';
import 'dart:io';
main() {
new HttpClient().getUrl(Uri.parse('http://foo.bar/foo.txt'))
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) => response.transform(new Utf8Decoder()).listen(print));
}
或将其写入文件:
import 'dart:convert';
import 'dart:io';
main() {
new HttpClient().getUrl(Uri.parse('http://foo.bar/foo.txt'))
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) => response.pipe(new File('foo.txt').openWrite()));
}