1、android與php的交互php
javajava
文件先轉化成二進制,再壓縮成字節數組,以後base64轉化成字符串用於json傳輸android
String body = "Lorem ipsum shizzle ma nizle"; URL url = new URL("http://some.url/file.php?id=" + uid); URLConnection conn = url.openConnection(); conn.setDoOutput(true); conn.setRequestProperty("Content-encoding", "deflate"); conn.setRequestProperty("Content-type", "application/octet-stream"); DeflaterOutputStream dos = new DeflaterOutputStream(conn.getOutputStream()); dos.write(body.getBytes()); dos.flush(); dos.close();
phpios
$content = http_get_request_body(); $uncontent = gzuncompress($content);
2、ios與php的交互json
php接收gzip壓縮數組
gzdecode(base64_decode($json));//ios gzip uncompress
php接收zlib壓縮app
gzuncompress(base64_decode($json));//ios zlib uncompress