OkHttp的深入研究:Jesse Wilson(二)

20 篇文章 0 订阅

Announcing OkHttp

May 06, 2013

Android has two HTTP clients built-in:

  • Apache HTTP Client is stable yet basic.
  • HttpURLConnection supports advanced features, but suffers a few annoying bugs on older devices.

At Square, we want it all: advanced features that work right on every device. We also want to ship new tech without waiting for new Android releases.

OkHttp is our new open source HTTP client for Android and Java. Our goal is to build the most robust, most efficient HTTP client.

Robust

Flaky networks are a fact of life, especially on mobile. OkHttp employs a few strategies to automatically recover should a connection fail.

For example, if your web service is hosted in multiple data centers for redundancy, OkHttp will attempt each IP address until it finds one that works. It also recovers from failed TLS handshakes and troublesome proxy servers.

The code is based on the latest version of Android’s HttpURLConnection, which has been battle-tested against real-world web servers.

Efficient

The fastest download is the one you don’t have to make. OkHttp includes an integrated response cache. Unlike an application-level cache, the integrated cache uses conditional requests to extend the life of stale resources.

When OkHttp does hit the network, it uses transparent response compression and a sophisticated connection pool. These on-by-default optimizations save bandwidth and reduce latency.

My favorite feature is the SPDY backend. This is Google’s efficient new wire transport layer that is the starting point for the new HTTP 2.0 draft. SPDY enables multiple concurrent requests to share a single socket. This lowers the cost of HTTPS so you no longer have to choose between security and performance.

Give it a try!

If you’ve written an Android app, OkHttp may improve the speed & reliability of your networking. It supports both the HttpURLConnection and HttpClient APIs so you can upgrade painlessly.

If you’re writing a new app, the project website has code examples to get you started.

Get OkHttp from Maven or download it from the project website.

This post is part of Square’s “Seven Days of Open Source” series.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值