编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

两分钟了解OkHttp(附英文)

wxchong 2024-06-10 17:02:41 开源技术 16 ℃ 0 评论

常见的Java 调用HTTPS/HTTP接口有三种方式,第一种是apache的HTTP工具库,第二种是JDK的提供的工具库,第三种就是我们今天要说的网络通信库OkHttp。OkHttp是有名的Square公司提供的开源项目,主要应用在Android端和Java端。

Introduction

HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP efficiently makes your stuff load faster and saves bandwidth.

HTTP是现代应用常用的一种交换数据和媒体的网络方式。高效地执行HTTP可以让您的东西加载得更快,并节省带宽。

OkHttp is an HTTP client that’s efficient by default:

OkHttp是一个默认高效的HTTP客户端。

HTTP/2 support allows all requests to the same host to share a socket.

支持HTTP/2,允许所有同一个主机地址的请求共享同一个socket连接

Connection pooling reduces request latency (if HTTP/2 isn’t available).

连接池减少请求延时(如果HTTP/2不可用)

Transparent GZIP shrinks download sizes.

透明的GZIP压缩减少响应数据的大小

Response caching avoids the network completely for repeat requests.

响应缓存避免一些完全重复的请求

Using OkHttp is easy. Its request/response API is designed with fluent builders and immutability. It supports both synchronous blocking calls and async calls with callbacks.

OkHttp的使用是非常简单的. 它的请求/响应 API 使用构造器模式builders来设计,它支持阻塞式的同步请求和带回调的异步请求。

英文选自官网 https://square.github.io/okhttp/

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表