[Android] HttpURLConnection or Apache Http client, androidapache

Source: Internet
Author: User

[Android] HttpURLConnection or Apache Http client, androidapache
There are two methods for network requests on Android, one is HttpURLConnection that comes with java, and the other is Http Clinet of Apache. But it is better to choose two methods? Excerpt from the official Android blog:
Which client is best?
Apache HTTP client has fewer bugs on Eclair and Froyo. It is the best choice for these releases.


For Gingerbread and better, HttpURLConnection is the best choice. its simple API and small size makes it great fit for Android. transparent compression and response caching reduce network use, improve speed and save battery. new applications shocould use HttpURLConnection; it is where we will be spending our energy going forward.


Before Android 2.3, you 'd better select Apache Http client. In Android 2.3 and later, select HttpURLConnection.
If you are interested, you can study the Volley framework:

            if (Build.VERSION.SDK_INT >= 9) {                stack = new HurlStack();-->HttpURLConnection             } else {                // Prior to Gingerbread, HttpUrlConnection was unreliable.                // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html                stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); -->Apache Http client            }


Original article: http://android-developers.blogspot.sg/2011/09/androids-http-clients.html

How to implement a simple network connection application in Android

Note: To perform the network operations described in this lesson, the manifest file of your application must contain the following permissions: 1 2 <uses-permissionandroid: name = "android. permission. INTERNET "/> <uses-permissionandroid: name =" android. permission. ACCESS_NETWORK_STATE "/> select an HTTP Client Choose an HTTP Client. Most Android apps connected to the network use HTTP to send and receive data. Android includes two HTTP clients: HttpURLConnection and Apache HttpClient, which support HTTPS, stream upload and download,
Configurable timeout, IPv6, and connection pool. We recommend that you use HttpURLConnection in android applications whose version is "ginger pie" (android2.3) or later,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.