The difference between HTTP 1.0 and http1.1
On a TCP connection
Only one TCP channel should be established after 1.1 each time
http1.0 each request requires a new TCP connection and the connection cannot be reused.
The http1.1 request can be sent on top of the last TCP connection requested, and the connection can be reused.
A bit is to reduce the overhead of repeating the TCP three handshake and improve efficiency.
Note: In the same TCP connection, the new request needs to wait until the last request receives a response before sending
URLConnection conn = Url.openconnection ();
To set common request properties
Conn.setrequestproperty ("Accept", "*/*");
Conn.setrequestproperty ("Connection", "keep-alive");
Conn.setrequestproperty ("User-agent", "mozilla/5.0 (Windows NT 6.1) applewebkit/537.36 (khtml, like Gecko) chrome/ 31.0.1650.63 safari/537.36 SE 2.X METASR 1.0 ");
HttpURLConnection and httpclient which is better
Select Use HttpClient before 2.3 because the long connection is closed when the httpurlconnection is turned off.
Sometimes the returned content length is-1;
After 2.3, choose to use HttpURLConnection, because the httpurlconnection small size, fast response, reduce power consumption
Httpresponsecache
Httpresponsecache is a cache framework that appears after 4.0, and now only supports Httpurlconnection,httpsurlconnection, Defaluthttpclient and androidhttpclient are not supported.
Code:
1 protected voidonCreate (Bundle savedinstancestate) {2 ...3 4 Try {5File Httpcachedir =NewFile (Context.getcachedir (), "http");6 LongHttpcachesize = 10 * 1024 * 1024;//Ten MiB7 Httpresponsecache.install (Httpcachedir, httpcachesize);8 Catch(IOException e) {9LOG.I (TAG, "HTTP Response cache Installation failed:" +e);Ten } One } A - protected voidOnStop () { - ... the -Httpresponsecache cache =httpresponsecache.getinstalled (); - if(Cache! =NULL) { - Cache.flush (); + } -}}
Understanding of Android HTTP