欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

APP端压缩上传,与PHP端解压实现

程序员文章站 2022-04-22 18:59:47
...
一、android与php的交互

java

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();

php

$content = http_get_request_body();$uncontent = gzuncompress($content);

二、ios与php的交互

php接收gzip压缩

gzdecode(base64_decode($json));//ios gzip uncompress

php接收zlib压缩

gzuncompress(base64_decode($json));//ios zlib uncompress