简体   繁体   English

使用或不使用http.Client的差异

[英]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.gethttp.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM