About Android HttpClient HttpURLConnection

Source: Internet
Author: User

About Android HttpClient HttpURLConnectionencounter a problem

When writing network access code with httpclient on Android studio, it was discovered that the class could not be imported and used .... Baidu after a while

Found a strong netizen has been solved. Related blog: Http://stackoverflow.com/questions/32153318/httpclient-wont-import-in-android-studio

The reason: in Android 2.3 and later, the use of httpurlconnection,httpclient is outdated, and in Android 2.2 and below, using the httpclient.

the difference between the two

Related blog: http://blog.csdn.net/guolin_blog/article/details/12452307

Here are some summaries of the article:

Less httpclient:bug, more API, and because of too many APIs, not conducive to upgrade maintenance and expansion

HttpURLConnection: Simple, easy to use and extensible.

HttpURLConnection Points of attention:

    • The gzip compression feature is turned on automatically. Which involves a knowledge point: Multi-threaded Breakpoint download file

If the function of the response compression is activated, the content-length in the HTTP response header will represent the compressed length, then using the Getcontentlength () method to remove the extracted data is wrong.

about how to turn off the gzip compression feature:urlconnection.setrequestproperty ("Accept-encoding", "identity");

    • https-
      We've also added some improvements to HTTPS in the Android 2.3 version, and now Httpsurlconnection will connect using SNI (Server Name indication). Enables multiple HTTPS hosts to share the same IP address. In addition, a number of compression and session mechanisms have been added. If the connection fails, it will automatically attempt to reconnect. This allows httpsurlconnection to connect to the latest servers more efficiently without compromising the compatibility of older versions.
    • Network data cache-android4.0 is added after
about choosing which is better

Choose the new one, of course: The API is easy to use. Google will also continue to maintain it. The future direction is certainly the performance is getting better, the function is more and more comprehensive

Currently you can also choose some open source projects that are widely accepted on GitHub.

    • Volley
    • Okhttp
    • Android-async-http

About Android HttpClient HttpURLConnection

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.