Use the Client class in the http Pub package for making multiple requests to the same server. Using Client keeps keep a persistent connection open to the server and is better than making multiple single requests.
import 'package:http/http.dart' as http; printResponseBody(response) { print(response.body.length); if (response.body.length > 100) { print(response.body.substring(0, 100)); } else { print(response.body); } print('...\n'); } main() async { var url = 'http://www.google.com/'; var client = new http.Client(); try { var response = await client.get('$url/search'); printResponseBody(response); response = await client.get('$url/doodles'); printResponseBody(response); } finally { client.close(); } }
查看更多关于Making multiple requests to the same server的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did129484