A macOS/iOS Flutter plugin that provides access to the Foundation URL Loading System.
Using the Foundation URL Loading System, rather than the socket-based dart:io HttpClient implemententation, has several advantages:
The easiest way to use this library is via the the high-level interface defined by package:http Client.
This approach allows the same HTTP code to be used on all platforms, while still allowing platform-specific setup.
late Client client; if (Platform.isIOS) { final config = URLSessionConfiguration.ephemeralSessionConfiguration() ..allowsCellularAccess = false ..allowsConstrainedNetworkAccess = false ..allowsExpensiveNetworkAccess = false; client = CupertinoClient.fromSessionConfiguration(config); } else { client = IOClient(); // Uses an HTTP client based on dart:io } final response = await client.get(Uri.https( 'www.googleapis.com', '/books/v1/volumes', {'q': 'HTTP', 'maxResults': '40', 'printType': 'books'}));
You can also use the Foundation URL Loading System API directly.
final url = Uri.https( 'www.googleapis.com', '/books/v1/volumes', {'q': 'HTTP', 'maxResults': '40', 'printType': 'books'}); final session = URLSession.sharedSession(); final task = session.dataTaskWithCompletionHandler(URLRequest.fromUrl(url), (data, response, error) { if (error == null && response!.statusCode == 200) { print(data!.bytes); } }); task.resume();