【发布时间】:2019-07-21 13:16:36
【问题描述】:
我试图了解 dart:io 库中 http package 和 HttpClient class 之间的区别。我的目的是知道什么时候应该使用哪个。我看到他们俩过去显然都在做同样的事情。
我看过这些问答:
- Choosing between package:html, dart:html, dart:io (class HttpClient) and package:http APIs to fetch HTTP resources
- How to make HTTPS request using HttpClient in dart?
- In a Dart console application, is there a library for an HTTP Request that doesnt require DOM access?
- How to do POST in Dart command line HttpClient
到目前为止,我认为这是正确的,但我的理解很模糊:
-
http为高电平,HttpClient为低电平 (source) -
http可以发帖请求,但HttpClient不能 (source) -
http和HttpClient(带有HttpClientRequest)都可以发出 GET 和 POST 请求 (source) -
http和HttpClient都可以在客户端和服务器上使用
总而言之,我想说每个人都可以做其他人可以做的任何事情,但是使用http 包更容易,因为这个包更高级。这个总结正确吗?
【问题讨论】: