Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
duwen update some comments e26784d Mar 7, 2019
0 contributors

Users who have contributed to this file

28 lines (24 sloc) 811 Bytes
import 'dart:async';
import 'package:dio/dio.dart';
class MyAdapter extends HttpClientAdapter {
DefaultHttpClientAdapter defaultHttpClientAdapter =
DefaultHttpClientAdapter();
@override
Future<ResponseBody> fetch(RequestOptions options,
Stream<List<int>> requestStream, Future cancelFuture) async {
Uri uri = options.uri;
// hook requests to google.com
if (uri.host == "google.com") {
return ResponseBody.fromString("Too young too simple!", 200, null);
}
return defaultHttpClientAdapter.fetch(options, requestStream, cancelFuture);
}
}
main() async {
var dio = new Dio();
dio.httpClientAdapter = MyAdapter();
Response response = await dio.get("https://google.com");
print(response);
response = await dio.get("https://baidu.com");
print(response);
}
You can’t perform that action at this time.