【问题标题】:How to zip/compress the Multipart HTTP request sent by the client如何压缩/压缩客户端发送的 Multipart HTTP 请求
【发布时间】:2012-10-25 00:04:44
【问题描述】:

我正在使用 apache httpclient 4.2 发送 Multipart HTTP PUT 请求。客户端必须上传 500 MB 左右的大尺寸二进制数据。因此需要压缩。 我希望压缩整个 Multipart HTTP 请求并通过 header Content-Encoding: gzip 通知服务器。我控制服务器和客户端代码。

注意:我知道我可以选择性地压缩大尺寸二进制数据而不是整个请求的方法,但现在我排除了这种方法。

httpclient 的 HttpRequestInterceptor 类不提供请求输入流的句柄或压缩请求的实体。

我在网上搜索并找到了一些相关链接(如下),但没有一个有效 1.http://old.nabble.com/compressing-multipart-request-from-custom-client-tt27804438.html#a27811350 2. http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#protocol_interceptors - 这个链接说“协议拦截器还可以操纵包含在消息中的内容实体——透明的内容压缩/解压缩就是一个很好的例子。”但不知道如何获得所需的功能。

如果可能的话,请给我一些示例代码。

【问题讨论】:

    标签: http compression gzip multipart multipartentity


    【解决方案1】:

    我终于能够通过

    解决这个要求
    1. 创建 org.apache.http.entity.mime.MultipartEntity 对象 reqEntity。
    2. 将压缩后的二进制部分添加到 HTTP 请求中

      ByteArrayBody binaryData = new ByteArrayBody(compressedData, "binary/octet-stream", "N/A"); binaryParts.add(binaryData); reqEntity.addPart("uniqueId", binaryPart);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-28
      • 1970-01-01
      • 2016-02-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多