项目环境: 对接的服务放在微服务中 提供接口给应用层调用 ,微服务放需要 接受参数 并且转换成压缩格式给 第三方服务

本来以为需要自己压缩,httpclint 中已经封装好了GzipCompressingEntity 对象
```java
StringEntity entity = new StringEntity(json, "UTF-8");
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
httpPost.setHeader("ICK-Content-Encoding", "gzip");
httpPost.setEntity(new GzipCompressingEntity(entity));

```java
接收应用层参数还是需要压缩:这边需要注意的是 压缩完成之后得到的byte[] 需要Base64.encodeBase64() 解压后需要Base64.decodeBase64()才能顺利还原
public static String compress(String str, String encoding) {
if (str == null || str.length() == 0) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip;
try {
gzip = new GZIPOutputStream(out);
gzip.write(str.getBytes(encoding));
gzip.close();
} catch (Exception e) {
e.printStackTrace();
}
return new String(Base64.encodeBase64(out.toByteArray()));
}

最新文章

  1. 【Android】开发中个人遇到和使用过的值得分享的资源合集
  2. 深入理解 JavaScript 变量的作用域和作用域链
  3. 自然语言9_NLTK计算中文高频词
  4. gitlab的使用方法
  5. Origin9.1如何使用原始数据(Raw Data)绘制风向玫瑰图
  6. SVN用法(merge,branch,switch)
  7. 5 HBase 常用Shell命令
  8. 桦仔 笔记7-徐 SQLSERVER日志记录机制
  9. Redis 中的数据类型及基本操作
  10. Xcode7.2中如何添加一个Empty Application模板
  11. FCC(ES6写法) Validate US Telephone Numbers
  12. 【Atcoder Grand Contest 011 F】Train Service Planning
  13. F - Count the Colors ZOJ - 1610 线段树染色(染区间映射)
  14. SQL LITE安装
  15. [SQL]查询整个数据库中某个特定值所在的表和字段的方法
  16. 【2017-02-28】C# 冒泡排序
  17. ACM-ICPC 2018 北京赛区网络预赛(9.22)
  18. 解决eclipse新建项目看不到src/main/java目录办法
  19. 后Hadoop时代的大数据技术思考:数据即服务
  20. 【Linux】进程优先级、进程nice值和%nice

热门文章

  1. Python CGI编程Ⅹ
  2. 在linux 下配置firewalld
  3. laravel短信验证
  4. ubuntu编译安装openssl
  5. tensorboard的log查看方法
  6. 洛谷P3294 [SCOI2016]背单词——题解
  7. php面向对象 练习
  8. oracle11g RMAN catalog的基本使用
  9. leetcode 72. 编辑距离
  10. ControlTemplate in WPF —— Button