[视频]OkHttp - Android Networking - History and Timeouts

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.

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

  1. HTTP/2 support allows all requests to the same host to share a socket.
  2. Connection pooling reduces request latency (if HTTP/2 isn’t available).
  3. Transparent GZIP shrinks download sizes.
  4. Response caching avoids the network completely for repeat requests.

OkHttp perseveres when the network is troublesome: it will silently recover from common connection problems. If your service has multiple IP addresses OkHttp will attempt alternate addresses if the first connect fails. This is necessary for IPv4+IPv6 and for services hosted in redundant data centers. OkHttp supports modern TLS features (TLS 1.3, ALPN, certificate pinning). It can be configured to fall back for broad connectivity.

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.

内容来源:mindorks.com,已获得原作者转载授权,请勿转载。