如何压缩 HTTP 请求正文

来源:互联网 发布:高校金融教学软件 编辑:程序博客网 时间:2024/06/06 03:49

转载地址   https://imququ.com/post/how-to-compress-http-request-body.html



$encoding = $_SERVER['HTTP_CONTENT_ENCODING'];

$rawBody = file_get_contents('php://input');

$body ='';

switch($encoding) {

case'gzip':

$body = gzdecode($rawBody);

break;

case'deflate':

$body = gzinflate(substr($rawBody,2,-4)) . PHP_EOL . PHP_EOL;

break;

case'deflate-raw':

$body = gzinflate($rawBody);

break;}

echo $body;



eg: post gzip的使用

Post  文件传输

header    Content-Encoding =  ‘gzip’ Content-Type='application/json'

body 二进制gzip 压缩过的文件