dio_http
A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File downloading, Timeout etc.
This package has been forked from Dio. To read why, click here.
Get started
Add dependency
dependencies:
dio_http: ^5.0.4
Already know Dio 3 and just want to learn about what’s new in Dio 4? Check out the Migration Guide!
Super simple to use
import 'package:dio_http/dio_http.dart';
void getHttp() async {
try {
var response = await Dio().get('http://www.google.com');
print(response);
} catch (e) {
print(e);
}
}
awesome-dio
?
A curated list of awesome things related to dio.
Plugins (support 4.0)
Plugins | Status | Description |
---|---|---|
dio_cookie_manager | A cookie manager for Dio | |
dio_http2_adapter | A Dio HttpClientAdapter which support Http/2.0 |
Table of contents
Examples
Performing a GET
request:
Response response;
var dio = Dio();
response = await dio.get('/test?id=12&name=wendu');
print(response.data.toString());
// Optionally the request above could also be done as
response = await dio.get('/test', queryParameters: {'id': 12, 'name': 'wendu'});
print(response.data.toString());
Performing a POST
request:
response = await dio.post('/test', data: {'id': 12, 'name': 'wendu'});
Performing multiple concurrent requests:
response = await Future.wait([dio.post('/info'), dio.get('/token')]);
Downloading a file:
response = await dio.download('https://www.google.com/', './xx.html');
Get response stream:
<div class=”highlight highlight-source-dart position-relative” data-snippet-clipboard-copy-content=”Response rs;
rs = await Dio().get(url,
options: Options(responseType: ResponseType.stream), // set responseType to `stream`
);
print(rs.data.stream); //response stream
“>
Response<ResponseBody> rs; rs = await Dio().get<ResponseBody>(url, options: Options(responseType: ResponseType.stream), // set responseType to `stream` ); print(rs.data.stream); //response stream