An adapter that combines HTTP/2 and dio. Supports reusing connections, header compression, etc.
Add the dio_http2_adapter
package to your
pubspec dependencies.
import 'package:dio/dio.dart';
import 'package:dio_http2_adapter/dio_http2_adapter.dart';
void main() async {
final dio = Dio()
..options.baseUrl = 'https://pub.dev'
..interceptors.add(LogInterceptor())
..httpClientAdapter = Http2Adapter(
ConnectionManager(idleTimeout: Duration(seconds: 10)),
);
Response<String> response;
response = await dio.get('/?xx=6');
for (final e in response.redirects) {
print('redirect: ${e.statusCode} ${e.location}');
}
print(response.data);
}
void main() async {
final dio = Dio()
..options.baseUrl = 'https://pub.dev'
..interceptors.add(LogInterceptor())
..httpClientAdapter = Http2Adapter(
ConnectionManager(
idleTimeout: Duration(seconds: 10),
onClientCreate: (_, config) => config.onBadCertificate = (_) => true,
),
);
}
void main() async {
final dio = Dio()
..options.baseUrl = 'https://pub.dev'
..interceptors.add(LogInterceptor())
..httpClientAdapter = Http2Adapter(
ConnectionManager(
idleTimeout: Duration(seconds: 10),
onClientCreate: (_, config) =>
config.proxy = Uri.parse('http://login:[email protected]:8888'),
),
);
}