[英]differences in using or not http.Client
going on Flutter documentation I found that fetching data was done, sometimes, by using http.Client
and sometimes not (just http.get
for example). 怎么回事扑文档我发现,获取数据是这样做,有时,通过使用
http.Client
有时不是(只是http.get
例如)。 So I was wondering the purpose of using http.Client
. 所以我想知道使用
http.Client
的目的。
These are the two sites where I found this: 这些是我发现的两个站点:
https://flutter.io/cookbook/networking/fetch-data/ https://flutter.io/cookbook/networking/fetch-data/
https://flutter.io/cookbook/networking/background-parsing/ https://flutter.io/cookbook/networking/background-parsing/
The http
package uses a default IOClient
when you use the convenience http.get
and http.post
methods. 当您使用便捷的
http.get
和http.post
方法时, http
包将使用默认的IOClient
。 However, sometimes you might want to use a specialized Client
, for example to change the default HTTPS certificate validation. 但是,有时您可能想使用专门的
Client
,例如,更改默认的HTTPS证书验证。 See this question . 看到这个问题 。
In this circumstance, you can create any Client
subclass and use it in the ways shown in your second link. 在这种情况下,您可以创建任何
Client
子类,并以第二个链接中显示的方式使用它。 It's rarely necessary, though so the syntax used in your first link is normally sufficient. 但这几乎没有必要,因此通常在第一个链接中使用的语法就足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.