首页 > 其他分享 >dart HttpSocket&HttpClient

dart HttpSocket&HttpClient

时间:2023-01-07 10:12:08浏览次数:50  
标签:HttpSocket await request dart close httpClient HttpClient

  1. HttpSocket
var server = await HttpServer.bind(
  InternetAddress.loopbackIPv4,
  4040,
);
print('Listening on localhost:${server.port}');

await for (HttpRequest request in server) {
  request.response
    ..write('Hello, world!')
    ..close();
}
  1. HttpClient
HttpClient httpClient = HttpClient();
HttpClientRequest request =
await httpClient.getUrl(Uri.parse("http://localhost:4444"));
HttpClientResponse response = await request.close();
var resData = await response.transform(utf8.decoder).join();
httpClient.close();

标签:HttpSocket,await,request,dart,close,httpClient,HttpClient
From: https://www.cnblogs.com/sqmw/p/17032165.html

相关文章