The current Android Access interface transmits data more in JSON format (simple and easy to parse across platforms), in order to save bandwidth and transfer time the server will often be gzip compressed before transmission, here are a few points to note.
1. For PHP server, the interface must be in the header with parameters Accept-encoding:gzip, deflate, or even if the background does gzip compression, will not be real compression.
2. If the data is gzip compressed by the server, the data needs to be gzip decompressed before the AP obtains the data:
Public String getresponsebodyasstring (HttpResponse response) throws IOException{Gzipinputstream Gzin; if (response.getentity () = null) {Header Header = Response.getfirstheader ("content-encoding"); if (header = null && header.getvalue (). toLowerCase (). IndexOf ("gzip")! =-1) {Gzin = new gzipinput Stream (Response.getentity (). getcontent ()); InputStreamReader ISR = new InputStreamReader (Gzin, "UTF-8"); BufferedReader br = new BufferedReader (ISR); StringBuilder sb = new StringBuilder (); String tmp; while ((TMP = Br.readline ()) = null) {sb.append (TMP); Sb.append ("\ r \ n"); } br.close (); Isr.close (); return sb.tostring (); } else {//otherwise normally returns return Entityutils.tostring (Response.getentity (), HTTP. UTF_8); }} else {return null; } }
The above describes the Android interface in the transfer of JSON data using gzip compression, including the exception aspects of the content, I hope the PHP tutorial interested in a friend helpful.