Dart中的HTTP和HttpClient之间的区别 [英] Difference between http and HttpClient in Dart

查看:377
本文介绍了Dart中的HTTP和HttpClient之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解 http程序包 HttpClient类。我的目的是知道何时应该使用它。我看到他们两个以前显然都做同样的事情。

I'm trying to understand the difference between the http package and the HttpClient class in the dart:io library. My purpose is to known when I should use which. I see both of them used to apparently do the same thing.

我已经看过这些Q& As:

I've seen these Q&As:

  • 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

到目前为止,我认为这是正确的,但我的理解很模糊:

This is what I think is true so far but my understanding is fuzzy:


  • http 是高级别,而 HttpClient 是低级别(

  • http 可以发出发布请求,但 HttpClient 不能(

  • http HttpClient (带有 HttpClientRequest )可以发出GET和POST请求(

  • http HttpClient 可以在客户端和服务器上使用

  • http is high level and HttpClient is low level (source)
  • http can make post requests but HttpClient can't (source)
  • both http and HttpClient (with HttpClientRequest) can make GET and POST requests (source)
  • both http and HttpClient can be used on the client and the server

因此,总而言之,我想每个人都可以做其他也可以,但是使用 http 包更容易,因为这是更多高级。该摘要正确吗?

So to sum it up, I would say that each one can do anything that the other can as well, but it is easier to use the http package since this one is more high-level. Is that summary correct?

推荐答案

http 包是对 dart:io dart:html

因此,如果要在浏览器和其他发出HTTP请求的平台之间共享代码,则最好使用 http 包。然后,代码将随处可见。

So if you want to share code between browser and other platforms that makes HTTP requests, then it's best to use the http package. Then the code will just work everywhere.

如果您不关心浏览器,请使用最喜欢的API。在Flutter中, http 包只包装了 dart:io HttpClient

If you don't care about the browser use what API you like best. In Flutter the http package just wraps dart:io's HttpClient.

这篇关于Dart中的HTTP和HttpClient之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆