http package
- Add 
httppackage topubspec.yamlfile: 
dependencies:
  http: ^0.13.1
- Install package from the command line:
 
pub get
- Send GET request:
 
We can use get() function to send GET request to the given URL. Function returns a Future that completes to Response object.
import 'package:http/http.dart' as http;
void main() async {
  var url = Uri.parse('https://httpbin.org/get');
  var response = await http.get(url);
  String content = response.body;
  print(content);
}
Or we can use read() function which returns a Future that completes to response body.
import 'package:http/http.dart' as http;
void main() async {
  var url = Uri.parse('https://httpbin.org/get');
  String content = await http.read(url);
  print(content);
}
Leave a Comment
Cancel reply