【问题标题】:Gzip Json requestGzip Json 请求
【发布时间】:2013-12-11 20:16:59
【问题描述】:

您好,我有以下类型的 json 对象,在来自 android 的一个请求中上传了很多文件和内容,图片数量可能会有所不同,并且可能比以下示例更多。示例中还有很多其他小键值,例如地址、电话等

   {
        "pdf": "base64stringvalue",
        "name": "username",
        "picture": "base64string",
        "picture1": "base64string",
        "picture2": "base64string",
        "picture3": "base64string",
        "picture4": "base64string",
        "picture5": "base64string",
        "picture6": "base64string",
        "picture7": "base64string",
        "picture8": "base64string",
        "picture9": "base64string"
    }

我想 gZip 对象并且想知道这样做的最佳方法是什么,基于使用 gzip 资源一次(a)和多次(b)

(a)我应该在客户端上压缩整个 json 对象并在服务器上解压缩它

{"object":"gzipped(wholeObject)"}

(b) 我是否应该只压缩对象中的 base64string 值(基本上分别压缩和解压缩每个实体)和类似的东西

{
    "pdf": "gzipped(base64string)",
    "name": "username",
    "picture": "gzipped(base64string)",
    "picture1": "gzipped(base64string)",
    "picture2": "gzipped(base64string)",
    "picture3": "gzipped(base64string)",
    "picture4": "gzipped(base64string)",
    "picture5": "gzipped(base64string)",
    "picture6": "gzipped(base64string)",
    "picture7": "gzipped(base64string)",
    "picture8": "gzipped(base64string)",
    "picture9": "gzipped(base64string)"
}

【问题讨论】:

  • 什么你不压缩它在 HTTP 级别。只需将您的数据压缩后发布即可。

标签: c# android asp.net gzip


【解决方案1】:

使用 Gzip,数据越大,压缩效果越好。

要了解它的工作原理,您可能需要阅读details about gzip algorithm

所以最好的解决方案是:

{"object":"gzipped(wholeObject)"}

但最好的方法是在通过 HTTP 发送之前压缩该值。为此,只需在您的请求中,设置您接受 Gzip:

Accept-Encoding: gzip, deflate

在你的回复中,告诉它是 GZip 编码的:

Content-Encoding: gzip

更多信息请关注Wikipedia

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-12
    • 2017-09-15
    • 2019-05-07
    • 1970-01-01
    相关资源
    最近更新 更多