Android Network Frameworks



HttpClient, HttpUrlConnection and OkHttp

Before Android Gingerbread(2.3) HttpUrlConnection is not stable cause it has some un-fixed bugs. So HttpClient is recommended as default. Since Gingerbread, the bugs are fixed, and HttpUrlConnection is more lightweight and more easy to maintain.

Both HttpClient and HttpUrlConnection are developed based on HTTP, when OkHttp based on HTTP and SPDY. That is said, OkHttp would be quicker and more efficiently.


  • Cancelable false
  • Support network change false
  • Parallel work support: not simple
  • May lead to memory leak (Activity has been recycled)
  • different behavior varies on platform-version

Volley, Retrofit and android-async-http



  • High level API to make asynchronous RESTful HTTP request.
  • Elegant and robust Request queue.
  • Extension architecture allows developers to implement custom request and response handling mechanism
  • Able to use external HTTP client library (like OkHttp)
  • Robust request caching policy.
  • Support image loading, and custom view for loading image easily.
  • Max waiting queue size: 11, cannot be changed
  • Max parallel capacity: default 4, can be changed.
  • StringRequest, JsonRequest supported.


  • Easy to use RESTful API ( by annotation)
  • Use OkHttp default. (which is faster than HttpClient or HttpUrlConnection)
  • NIO support.
  • Faster than Volley.
  • Auto parse Json by Gson (default). And jackson, simplexml, protobuf also supported.
  • Can custom thread pool size
  • Simply for Web Service. Image load not support,


  • Asynchronous Http Request, handle responses in anonymous callbacks.
  • HTTP requests happen outside the UI thread.
  • Thread Pool for capping concurrent resource usage.
  • GET/POST params builder
  • Multipart file uploads without using third part libraries.
  • Automatic smart request retries.
  • Automatic gzip decode.
  • Built-in response parsing in to JSON(JsonHttpResponseHandler)
  • Max connections default: 10, can be changed.


  • Json parse

    Retrofit has auto json parser.

  • Cookie Handler

  • Retry mechanism

    Retrofit has no retry mechanism.

  • Headers

  • Error handling


  • Memory use
  • Speed


  • OkHttp的body只可取一次,第二次再取则为空。
blog comments powered by Disqus