File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,13 @@ class WebUtil {
88 static final HttpClient _client = HttpClient ();
99
1010 /// HTTP GET request.
11- static Future <HttpClientResponse > get (String base , String api) async {
11+ static Future <HttpClientResponse > get (String base , String api,
12+ {Map <String , dynamic > headers = const {}}) async {
1213 if (! base .endsWith ('/' )) base += '/' ;
1314 final request = await _client.getUrl (Uri .parse ('$base $api ' ));
15+ for (final header in headers.entries) {
16+ request.headers.add (header.key, header.value);
17+ }
1418 return request.close ();
1519 }
1620
@@ -19,7 +23,8 @@ class WebUtil {
1923 [Map <String , dynamic > headers = const {}]) async {
2024 if (! base .endsWith ('/' )) base += '/' ;
2125 if (! (body is List ) && ! (body is Map )) {
22- throw Exception ('body must be a List or Map' );
26+ throw ArgumentError .value (
27+ body.runtimeType, 'body' , 'body must be a List or Map' );
2328 }
2429 final request = await _client.postUrl (Uri .parse ('$base $api ' ));
2530 for (MapEntry e in headers.entries) {
You can’t perform that action at this time.
0 commit comments