Okhttp 或 HTTPClient :哪个提供更好的功能和更高的效率? [英] Okhttp or HTTPClient : Which offers better functionality and more efficiency?

查看:339
本文介绍了Okhttp 或 HTTPClient :哪个提供更好的功能和更高的效率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了发出http请求,JAVA中有一些API可供选择,例如Apache HttpClient和Okhttp.Apache HttpClient 成熟且应用广泛,Okhttp 似乎越来越流行(我不确定).

To make a http request, there're some APIs alternative in JAVA, such as Apache HttpClient and Okhttp. Apache HttpClient is mature and widely used, and Okhttp seems to be more and more popular(I'm not sure).

我想知道的是,哪个更好,或者 Apache HttpClient 是否有一些 Okhttp 没有的功能,或者相反?大多数情况下,我是在服务器端谈论的,谈论在 Android 应用程序中使用也很不错.

What I wondered is, which is better, or does Apache HttpClient has some feature that Okhttp doesn't have, or the other way round? Mostly, I'm talking in server side, it's also very nice to talk about using in Android App.

我希望能列出一些要点,这样我就可以弄清楚Apache HttpClient和Okhttp之间的区别.

I hope some points could be listed, therefore I can figure out the differences between Apache HttpClient and Okhttp.

参考:

URLConnection 和 HttpClient 之间有个问题:URLConnection 或 HTTPClient :哪个提供更好的功能和更高的效率?

There's a question between URLConnection and HttpClient: URLConnection or HTTPClient : Which offers better functionality and more efficiency?

推荐答案

我建议使用 okhttp.原因如下:https://github.com/square/okhttp/issues/3472

I suggest to use okhttp. Here is the reason: https://github.com/square/okhttp/issues/3472

OkHttp 具有 HTTP/2、内置响应缓存、Web 套接字和更简单的 API.它有更好的默认设置,更容易有效使用.它有一个更好的 URL 模型、一个更好的 cookie 模型、一个更好的标头模型和一个更好的调用模型.OkHttp 使取消呼叫变得容易.OkHttp 精心管理了安全且广泛兼容的 TLS 默认值.Okhttp 与 Retrofit 一起使用,这是一个出色的 REST API.它也适用于 Okio,这是一个很棒的数据流库.OkHttp 是一个小库,有一个小依赖(Okio),需要学习的代码更少.OkHttp 部署更广泛,有 10 亿台 Android 4.4+ 设备在内部使用它.

OkHttp has HTTP/2, a built-in response cache, web sockets, and a simpler API. It’s got better defaults and is easier to use efficiently. It’s got a better URL model, a better cookie model, a better headers model and a better call model. OkHttp makes canceling calls easy. OkHttp has carefully managed TLS defaults that are secure and widely compatible. Okhttp works with Retrofit, which is a brilliant API for REST. It also works with Okio, which is a great library for data streams. OkHttp is a small library with one small dependency (Okio) and is less code to learn. OkHttp is more widely deployed, with a billion Android 4.4+ devices using it internally.

这篇关于Okhttp 或 HTTPClient :哪个提供更好的功能和更高的效率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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