-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. add DioHttpHeaders class
- Loading branch information
duwen
committed
Mar 1, 2019
1 parent
f31f88c
commit 15de2ea
Showing
11 changed files
with
601 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.