http请求body怎么压缩
- 添加请求头
Content-Encoding: gzip
- 添加前置处理器 BeanShell
importorg.apache.commons.io.IOUtils; importjava.util.zip.GZIPOutputStream; StringbodyString=sampler.getArguments().getArgument(0).getValue(); byte [] requestBody=bodyString.getBytes(); ByteArrayOutputStreamout=newByteArrayOutputStream(requestBody.length); GZIPOutputStreamgzip=newGZIPOutputStream(out); gzip.write(requestBody); gzip.close(); sampler.getArguments().getArgument(0).setValue(out.toString(0));
例子
DDD,tag1=a,tag2=f,tag3=c,tag4=e,tag5=g age=24i,money=7.645900,new=853049.690396,kaiche=false${__unescape(\n)}DDD,tag1=a,tag2=f,tag3=c,tag4=e,tag5=g age=24i,money=7.645900,new=853049.690396,kaiche=false
压缩
未压缩
压缩后,数据包明显变小,传输会变得更容易,也能节省带宽
当然,服务器也会多一个解压数据的操作,也会消耗CPU的