There's an HttpClient class in the IO library for making HTTP requests:
import 'dart:io';
void main() {
HttpClient client = new HttpClient();
client.getUrl(Uri.parse("http://www.dartlang.org/"))
.then((HttpClientRequest request) {
return request.close();
})
.then(HttpBodyHandler.processResponse)
.then((HttpClientResponseBody body) {
print(body.body);
});
}
Update: Since HttpClient is fairly low-level and a bit clunky for something simple like this, the core Dart team has also made a pub
package, http
, which simplifies things:
import 'package:http/http.dart' as http;
void main() {
http.get('http://pub.dartlang.org/').then((response) {
print(response.body);
});
}
I found that the crypto
package was a dependency, so my pubspec.yaml
looks like this:
name: app-name
dependencies:
http: any
crypto: any