这个问题是问题here的延伸.我使用下面复制的代码here来压缩一个JSONObject.

String foo = "value";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null;

try {
    gzos = new GZIPOutputStream(baos);
    gzos.write(foo.getBytes("UTF-8"));
} finally {
    if (gzos != null) try { gzos.close(); } catch (IOException ignore) {};
}

byte[] fooGzippedBytes = baos.toByteArray();

I am using a DefaultHttpClient to send this compressed JSONObject to server(the code is in my control).

My Question

What header should I use in my request? I am using request.setHeader("Content-type", "application/json"); for sending JSON to server?

推荐答案

要通知服务器您正在发送gzip编码的数据,请发送Content-Encoding头,而不是Accept-Encoding头.

Json相关问答推荐

服务器不返回JSON

盒子图显示不正确

NIFI-我需要数组的信息,但只需要第一个信息

无法从MongoDB集合中检索正确的文档

(已回答)JSON 读取函数返回未定义而不是预期值 - Typescript

PowerShell - 将 json 添加到文件内容

使用 jolt 将对象数组转换为数组

从 Inno Setup 中的 JSON 文件的每个对象中读取特定字符串

如何将复杂的 JSON 反序列化为 Rust 类型?

Jolt 变换 - 如何用字段值重命名字段?

xidel:是否可以从 JSON 对象中检索特定的嵌套值?

为什么根据其他工具,来自 aws rds 的 JSON 在 Docker 中格式错误运行?

Golang / Go - 如果 struct 没有字段,如何将其编组为空?

如何判断 Json 对象中是否存在键并获取其值

在 Apache Spark 中读取多行 JSON

IE中Json响应下载(7~10)

Spring Security 和 JSON 身份验证

有没有办法使用 Jackson 将 Map 转换为 JSON 表示而不写入文件?

如何对 Javascript 对象进行排序,或将其转换为数组?

log4j 支持 JSON 格式吗?